<?php
namespace Home\Controller;
use Think\Controller;
use Think\Upload;
use Org\Util;
class ProductController extends Controller {
	
	public function __construct(){
		parent::__construct();
		
		if(empty($_SESSION['user']))
		{
			 
			 $this->error('对不起,您还没有登录!请先登录!', U('Login/login'), 1);
			//$this->redirect("Login/login"); 
			/*echo "<script>alert('对不起,您还没有登录!请先登录!');top.location.href='index.php/Home/Login/login.html';</script>";
			*/
			/*echo "<script>alert('对不起,您还没有登录!请先登录!');top.location.href='http://192.168.0.137/index.php/Home/Login/login.html';</script>";*/
			//$this->redirect("Login/login"); 
		}
	}
	
	//显示产品流转页面
	public function product_circulation(){

		//分页处理数据
		//分页处理

		$count = M('circulation')->field('id')->count();
		$pagesize = $_POST['pagesize']?$_POST['pagesize']:10;
		$nowpage = $_POST['page']?$_POST['page']:1;
		$limit = ''.($pagesize*$nowpage-$pagesize).','.$pagesize;
		$list = M('circulation')->order('id  desc')->limit($limit)->select();
		$countpage = ceil($count/$pagesize);
		

		$this->assign('page',$page);
		$this->assign('countpage',$countpage);
		$this->assign('nowpage',$nowpage);
		$this->assign('pagesize',$pagesize);
		$this->assign('count',$count);
		$this->assign('list',$list);

		//先检测该页面是否有提交的数据
		if(IS_POST){

			$data = I('post.');
			//echo $data['pagesize']."<br>".$data['page'];exit; 
			foreach ($data as $k => $v) {
				if($data[$k]!=''){
					$c[$k] = $data[$k]; 
				}
			}


			  //所有平台名称获取
			  $platform_name = M('platform');
				//只有一条记录， 所以用 find . 查找平台信息
			  $data = $platform_name->find(); 

			  //获取流程表circulation 的数据
		      $circulation = M('circulation');
			  $cir = $circulation->order('time12 desc')->select();
				
				//赋值模板	
			  if($data){
					$this->assign('data',$data);
			  }

				
			  $this->assign('cir',$cir);

			  

			  //where 语句拼装
			  $where=array();

			  if($c['sku']){
			  	$where['sku'] = array('eq',$c['sku']);
			  }

			  // time1 => 交摄时间
			  if($c['shoot_time_start'] && $c['shoot_time_end']){
			  	$where['time1'] = array(array('egt',$c['shoot_time_start']) , array('elt',$c['shoot_time_end']." 23:59:59"));
			  }

			  
			  // time2 => 完成图片时间
			  if($c['pic_time_start'] && $c['pic_time_end']){
			  	$where['time2'] = array(array('egt',$c['pic_time_start']) , array('elt',$c['pic_time_end']." 23:59:59"));
			  }

			  // time3 => 上传完成时间

			  if($c['up_time_start'] && $c['pic_time_end']){
			  	$where['time3'] = array(array('egt',$c['up_time_start']) , array('elt',$c['up_time_end']." 23:59:59"));
			  }

			  // platform => platform ?
			  if($c['platform']){
			  	$i = $c['platform']+3; //platform1 => time(1+3)
			  	$res_=$circulation->field('time'.$i)->where(array('sku'=>$c['sku']))->find();
			  	//dump($res_);exit;
			  	if($res_['time'.$i]){
			  		//echo "Hello";exit;
			  		$where['time'.$i] = array(array('neq',''));  //默认是 and 
			  	}else{
			  		$this->error('请检查 sku 是否输入;  或该产品未在该平台上架');
			  	}
			  	
			  }
			  //echo $c['platform'];exit;
			  $res_data=$circulation->where($where)->select();
			  //dump($res_data);exit;
			  $this->assign('res_data',$res_data);
			  return $this->display('search_show_cir');








		}


		$platform_name = M('platform');
		//只有一条记录， 所以用 find . 查找平台信息
		$data = $platform_name->find(); 
		$circulation = M('circulation');
		$cir = $circulation->order('id desc')->limit($limit)->select();
		//dump($data);exit;
		if($data){
			$this->assign('data',$data);
		}

		
		$this->assign('cir',$cir);
		//dump($cir);exit;
		
		return $this->display();
	}





	//处理上传的excel 并 导入数据库
	public function circulation_input(){
		//echo EXCEL;exit;
		if(IS_POST){
			$import_tpl = I('post.import_tpl'); 
			$upload = new \Think\Upload();
			//$upload->maxSize   =     3145728 ;// 设置附件上传大小
		    $upload->exts      =     array('xls', 'xlsx');// 设置附件上传类型
		    $upload->rootPath  =     THINK_PATH; // 设置附件上传根目录
		    $upload->savePath  =     '../Public/excel_tpl/'; // 设置附件上传（子）目录
		    $upload->subName   =     array('date','Ymd');
		    // 上传文件 
		    $info   =   $upload->upload();
		    if(!$info) {// 上传错误提示错误信息
	       		 $this->error($upload->getError());

	   	    }else{// 上传成功
	        	 //$this->success('上传成功！','product_circulation','1');
	        	 import("Org.Util.PHPExcel");
		         import("Org.Util.PHPExcel.Worksheet.Drawing");
		         import("Org.Util.PHPExcel.Writer.Excel2007");
		         import("Org.PHPExcel.Reader.Excel2007", '', '.php'); 
				 import("Org.Util.PHPExcel.Style.NumberFormat");
				 import("Org.Util.PHPExcel.Style.Alignment");
				 import("Org.Util.PHPExcel.Style.Color");
		         $objPHPExcel = new \PHPExcel();
		         //引入PHPExcel类
            	 
		         $objReader = new \PHPExcel_Reader_Excel2007();
		         //dump($info);exit;
		         //$filename = $info->getSaveName();
		         //echo $filename; exit;
		         $filepath = THINK_PATH . $info['excel_file']['savepath'] . $info['excel_file']['savename'];
		         //echo $filepath;exit;

		         //加载excel文件
		         $obj_load = $objReader->load($filepath);

		         //读取excel文件中的第一个工作表
	             $sheet = $obj_load->getSheet(0);
	             $allRow = $sheet->getHighestRow();    //取得总行数

	             //$allColumn = $sheet->getHighestColumn();    //取得总列数

	             
    	

			    //循环读取excel表格,读取一条,插入一条
    			//j表示从哪一行开始读取  从第二行开始读取，因为第一行是标题不保存
    			//$a表示列号
	            $flag = 1;

	            //当导入模板来自新增流程页
	            if($import_tpl=='circulation'){
		    			for($j=2;$j<=$allRow;$j++){

		    				/*
		    				导入数据的时候，如果不注意时间的格式问题，后台读到的数据会变为40740.74363425939(即读到的是总的天数，excel中的时间为2011-07-16  17:50:50)

		    				那么  ： 40740.74363425939这个数据是怎么来的
		    				  * excel的时间从1900-01-01 00:00:00开始算起，40740.74363425939表示从开始时间到2011-07-16  17:50:50一共有多少天

		    				  解决办法：

							1、php是从1970-01-01 00:00:00 开始计算的，和1900-01-01 00:00:00相差25567天； 
							2、如果要上传数据的人来关注时间格式显然不好； 
							3、php（其他语言也差不多）可以通过 date(‘Y-m-d H:i:s’, (40740.7436342593 - 25569) * 24*60*60)来转换，至于为什么是25569我也 不知道。 

							经过测试，确实有效
		    				*/
					    
					        $excel_data['sku'] = $obj_load->getActiveSheet()->getCell("A".$j)->getValue();//获取A(SKU)列的值
					        if($excel_data['sku'] instanceof PHPExcel_RichText){
					        	$excel_data['sku'] = $excel_data['sku']->__toString();
					        }

					        // 循环读取同一行的列， 把空的格子排除掉。
					        for($cell='B',$n=1;$cell<='L',$n<=12;$cell++,$n++){
					        	//echo $cell.$n."<br>";

					        	if($obj_load->getActiveSheet()->getCell($cell.$j)->getValue()){

					        		$excel_data['time'.$n] = date("Y-m-d",(intval($obj_load->getActiveSheet()->getCell($cell.$j)->getValue()) - 25569) * 24 * 60 * 60 ) ;//获取B(time1)列的值
					        	}
					        }

					        if($import_tpl=='circulation'){

						        	$w = M('circulation');
						        	//防止重复输入 sku
						        	$res_chk=$w->where(array('sku'=>$excel_data['sku']))->find();
									if($res_chk){
										$this->error('已经有该SKU ('.$excel_data['sku'].') 的信息了，请不要重复输入');
									}

						       		
						        	//写入数据库操作
						       		$res = $w->add($excel_data);


			   				 }

			   				if($res) {
						        	//写入一条数据 做一次标记最后统计看是否所有行都写入
						        	$flag =$flag+1;
						            //$this->success('表格已保存在服务器， 且表格数据成功导入','Product/product_circulation','1');
						            continue;
					            
							}else{
							         $this->error('导入表格数据写入失败，请检查表格数据格式 检查是否有奇怪的字符或者列数不同');
							    }

					    }
				}

			        /*  circulation   &&    offshelf   分割线 */
			        
			    //当导入模板来自 下架页面
			    if($import_tpl=='off_shelf'){

			        	for($j=2;$j<=$allRow;$j++){
			    
				       		 $excel_data['sku'] = $obj_load->getActiveSheet()->getCell("A".$j)->getValue();//获取A(SKU)列的值
						     if($excel_data['sku'] instanceof PHPExcel_RichText){
						        	$excel_data['sku'] = $excel_data['sku']->__toString();
						     }

						    if($obj_load->getActiveSheet()->getCell("B".$j)->getValue()){
						      		$excel_data['offshelf_time'] = date("Y-m-d",(intval($obj_load->getActiveSheet()->getCell("B".$j)->getValue()) - 25569) * 24 * 60 * 60 );//获取B(offshelf_time)
						  	}


						  	  //offshelf_reason
						  	$excel_data['offshelf_reason'] = $obj_load->getActiveSheet()->getCell("C".$j)->getValue();
						  	if($excel_data['offshelf_reason'] instanceof PHPExcel_RichText){
						        	$excel_data['offshelf_reason'] = $excel_data['offshelf_reason']->__toString();
						    }
						      

						        // 循环读取同一行的列， 把空的格子排除掉。
						        for($cell='D',$n=1;$cell<='K',$n<=8;$cell++,$n++){
						        	//echo $cell.$n."<br>";

						        	if($obj_load->getActiveSheet()->getCell($cell.$j)->getValue()){

						        		$excel_data['time'.$n] = date("Y-m-d",(intval($obj_load->getActiveSheet()->getCell($cell.$j)->getValue()) - 25569) * 24 * 60 * 60 ) ;//获取B(time1)列的值
						        	}
						        }

						        if($import_tpl=='off_shelf'){


						        	$w = M('off_shelf');
						       
						        	//写入数据库操作
						       		$res = $w->add($excel_data);


					   			}


						        if($res) {
						        	//写入一条数据 做一次标记最后统计看是否所有行都写入
						        	$flag =$flag+1;
						            //$this->success('表格已保存在服务器， 且表格数据成功导入','Product/product_circulation','1');
						            continue;
					            
							    }else{
							         $this->error('导入表格数据写入失败，请检查表格数据格式 检查是否有奇怪的字符或者列数不同');
							    }



				        }

				        

			    }

			    
			        
			       
			        //获取每行数据后，写入，一行一行写入数据库。
			        //开始判断要导入哪个表， 检查传递过来的身份信息。 看究竟是 circulation 还是 off_shelf

			    


			    
			       /*	echo $import_tpl."<br>";
			        dump($excel_data);exit;

			        */

			    
			    //dump($excel_data);exit;
			    //判断 flag 是否等于 allRow  如果相等，代表所有数据正确导入否则 有部分数据未导入。(共同部分)
			    if($flag == $allRow){
			    	//dump($excel_data);exit;
			    	$this->success('表格已保存在服务器， 且表格数据成功导入');exit;
			    }else{
			    	$this->error('有部分数据未导入。');exit;
			    }
			    
			}
			

			
	    }

	    return $this->display();

	}

		

		
	



	//添加产品流转过程
	public function circulation_post(){

		if(IS_POST){

			$data['sku'] = $_REQUEST['sku'];
			$data['product_developer'] = $_REQUEST['product_developer'];
			if($data['sku']){
				//$data['time12'] = date('Y-m-d');
				$write_data = M('circulation');

				//防止重复的 sku 输入
				$res_chk=$write_data->where(
						array(
							'sku'=>$data['sku'],
		
							)

						)->find();
				if($res_chk){
					$this->error('已经有该SKU的信息了，请不要重复输入');
				}
				$res = $write_data->add($data);
				//dump($res);exit;
				if($res){
					$this->success('成功新建流程',U('Product/product_circulation'),1);
				}
			}else{
				$this->error('请输入SKU 和 开发人员信息， SKU为必填');
			}
		}
	}

	//下载产品流转的模板
	public function circulation_tpl_download(){
		if(IS_GET){
			$data = I('get.');
			//dump($data);exit;
			//获取平台信息 ； 通用
			$platform = M('platform')->field('platform1,platform2,platform3,platform4,platform5,platform6,platform7,platform8')->select();
			if($data['tpl']=='offshelf'){
				
					
					//dump($platform);die;
					$excel_file_name = "下架信息记录模板";

					//排除空值
					foreach ($platform[0] as $k => $v) {
						if(!empty($v)){
							$data_header_arr[$k] = $v;
						}
						
					}

			}
			

			if($data['tpl']=='circulation'){

					//dump($platform);die;
					$excel_file_name = "新品上架流转模板";

					//排除空值
					foreach ($platform[0] as $k => $v) {
						if(!empty($v)){
							$data_header_arr[$k] = $v;
						}
						
					}

			}

			

			 import("Org.Util.PHPExcel");
		     import("Org.Util.PHPExcel.Worksheet.Drawing");
		     import("Org.Util.PHPExcel.Writer.Excel2007");
		     import("Org.Util.PHPExcel.Style.NumberFormat");
		     import("Org.Util.PHPExcel.Style.Alignment");
		     import("Org.Util.PHPExcel.Style.Color");

		     $objPHPExcel = new \PHPExcel();
		     //$objColor = new \PHPExcel.Style.Color();
		     
		     $fontStyle = $objPHPExcel->getActiveSheet();
		     
		      // 水平居中（位置很重要，建议在最初始位置）
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        
		        
		        // 垂直居中
		        $objPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
		        $objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
		        $objPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
		        $objPHPExcel->getActiveSheet()->getStyle('E')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
		        $objPHPExcel->getActiveSheet()->getStyle('F')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
		        $objPHPExcel->getActiveSheet()->getStyle('G')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);

		     

		     /*右键属性所显示的信息*/
		     $objPHPExcel->getProperties()->setCreator("星爱")       //作者
                           ->setLastModifiedBy("falcon")       //最后一次保存者
                           ->setTitle('模板')      //标题
                           ->setSubject('模板')    //主题
                           ->setDescription('导出数据')     //描述
                           ->setKeywords("excel")           //标记
                          ->setCategory("result file");     //类别

             //设置当前的表格 
    		$objPHPExcel->setActiveSheetIndex(0);
    		$objWriter = new \PHPExcel_Writer_Excel2007($objPHPExcel);


    		


    		
    		//$last_platform = end($plat_arr);


	    		if($data['tpl']=='circulation'){
	    			$d = $objPHPExcel->getActiveSheet();
	    			$d->setCellValue('A1','sku');
	    			$d->setCellValue('B1','交摄时间');
	    			$d->setCellValue('C1','完成图片时间');
	    			$d->setCellValue('D1','上传完成时间');
	    			$C='D';
	    		}

	    		if($data['tpl']=='offshelf'){
					$d = $objPHPExcel->getActiveSheet();
	    			$d->setCellValue('A1','sku');
	    			$d->setCellValue('B1','产品下架时间');
	    		    $d->setCellValue('C1','下架原因');
	    		    $C='C';
	    		}

    		foreach ($data_header_arr as $k => $v) {
    			//excel 表头的列字母 往下增加  A1 B1  C1 ....Z1
    			$C++;
	    
	    			
	    			$d->setCellValue($C.'1',$v);
	    			
    		}

    			

    		/* 生成到浏览器，提供下载 */ 
		    ob_end_clean();  //清空缓存             
		    header("Pragma: public");
		    header("Expires: 0");
		    header("Cache-Control:must-revalidate,post-check=0,pre-check=0");
		    header("Content-Type:application/force-download");
		    header("Content-Type:application/vnd.ms-execl");
		    header("Content-Type:application/octet-stream");
		    header("Content-Type:application/download");
		    header('Content-Disposition:attachment;filename="'.$excel_file_name.'.xlsx"');
		    header("Content-Transfer-Encoding:binary"); 
		    $objWriter->save('php://output');
    		


		}
	}

	public function product_summary(){
		$name = $_SESSION['user'];
		$acc_type = M('account')->field('cost_price,supplier')->where(array('username'=>$name))->find();
		$sku 					= I('get.sku','','htmlspecialchars');
		$default_styles 		= I('get.default_styles','','htmlspecialchars');
		$independent_product 	= I('get.independent_product','','htmlspecialchars');
		$brand 					= I('get.brand','','htmlspecialchars');
		$logo 					= I('get.logo','','htmlspecialchars');
		$product_material 		= I('get.product_material','','htmlspecialchars');
		$product_type 			= I('get.product_type','','htmlspecialchars');
		$weight_before 			= I('get.weight_before','','htmlspecialchars');
		$weight_after			= I('get.weight_after','','htmlspecialchars');
		$cost_price_before 		= I('get.cost_price_before','','htmlspecialchars');
		$cost_price_after		= I('get.cost_price_after','','htmlspecialchars');
		$ali_lt_start 			= I('get.ali_lt_start','','htmlspecialchars');
		$ali_lt_end 			= I('get.ali_lt_end','','htmlspecialchars');
		$ali_gt_start			= I('get.ali_gt_start','','htmlspecialchars');
		$ali_gt_end 			= I('get.ali_gt_end','','htmlspecialchars');
		$aliexpress_start 		= I('get.aliexpress_start','','htmlspecialchars');
		$aliexpress_end 		= I('get.aliexpress_end','','htmlspecialchars');
		$ioffer_start 			= I('get.ioffer_start','','htmlspecialchars');
		$ioffer_end 			= I('get.ioffer_end','','htmlspecialchars');
		$custom_one 			= I('get.custom_one','','htmlspecialchars');
		$custom_two 			= I('get.custom_two','','htmlspecialchars');
		$custom_three			= I('get.custom_three','','htmlspecialchars');
		$custom_four 			= I('get.custom_four','','htmlspecialchars');
		$supplier 				= I('get.supplier','','htmlspecialchars');
		$buyer 					= I('get.buyer','','htmlspecialchars');
		$starttime 				= I('get.starttime','','htmlspecialchars');
		$endtime 				= I('get.endtime','','htmlspecialchars');
		
		$pageNo=empty($_REQUEST['pageNo'])?1:$_REQUEST['pageNo'];
		$pageSize=empty($_REQUEST['pageSize'])?100:$_REQUEST['pageSize'];
		
		$res = D('product')->searchList($sku,$default_styles,$independent_product,$brand,$logo,$product_material,$product_type,$weight_before,$weight_after,$cost_price_before,$cost_price_after,$ali_lt_start,$ali_lt_end,$ali_gt_start,$ali_gt_end,$aliexpress_start,$aliexpress_end,$ioffer_start,$ioffer_end,$custom_one,$custom_two,$custom_three,$custom_four,$supplier,$buyer,$starttime,$endtime,$pageNo,$pageSize);

		
		$custom = M("custom");
		$custom_info = $custom->find();
		$where['status'] = '1';
		$product =D('product'); 
		
		
		$brand_info 	= $product->field("brand")->group('brand')->select();
		$material_info 	= $product->field("product_material")->group('product_material')->select();
		$type_info 		= $product->field("product_type")->group('product_type')->select();
		$custom_1 	= $product->field("custom_one")->group('custom_one')->select();
		$custom_2 	= $product->field("custom_two")->group('custom_two')->select();
		$custom_3 	= $product->field("custom_three")->group('custom_three')->select();
		$custom_4 	= $product->field("custom_four")->group('custom_four')->select();
		$supplier_info 	= $product->field("supplier")->group('supplier')->select();
		$buyer_info 	= $product->field("buyer")->group('buyer')->select();
		
		$product_list 	= $res['product_list'];
		$count 			= $res['count'];

		$this->assign('acc_type',$acc_type);
		$this->assign("brand_info",$brand_info);
		$this->assign("material_info",$material_info);
		$this->assign("type_info",$type_info);
		$this->assign("custom_1",$custom_1);
		$this->assign("custom_2",$custom_2);
		$this->assign("custom_3",$custom_3);
		$this->assign("custom_4",$custom_4);
		$this->assign("supplier_info",$supplier_info);
		$this->assign("buyer_info",$buyer_info);
		$this->assign("product_list",$result);
		$this->assign("count",$count);
		$this->assign("custom",$custom_info);
		$this->assign("product_list",$product_list);
		
		
		$this->assign("sku",$sku);
		$this->assign("default_styles",$default_styles);
		$this->assign("independent_product",$independent_product);
		$this->assign("brand",$brand);
		$this->assign("logo",$logo);
		$this->assign("product_material",$product_material);
		$this->assign("product_type",$product_type);
		$this->assign("weight_before",$weight_before);
		$this->assign("weight_after",$weight_after);
		$this->assign("cost_price_before",$cost_price_before);
		$this->assign("cost_price_after",$cost_price_after);
		$this->assign("ali_lt_start",$ali_lt_start);
		$this->assign('ali_lt_end',$ali_lt_end);
		$this->assign("ali_gt_start",$ali_gt_start);
		$this->assign("ali_gt_end",$ali_gt_end);
		$this->assign("aliexpress_start",$aliexpress_start);
		$this->assign("aliexpress_end",$aliexpress_end);
		$this->assign("ioffer_start",$ioffer_start);
		$this->assign("ioffer_end",$ioffer_end);
		$this->assign("custom_one",$custom_one);
		$this->assign("custom_two",$custom_two);
		$this->assign("custom_three",$custom_three);
		$this->assign("custom_four",$custom_four);
		$this->assign("supplier_search",$supplier);
		$this->assign("buyer_search",$buyer);
		$this->assign("starttime",$starttime);
		$this->assign('endtime',$endtime);
		
		$this->display();
	}
	
				
	
	public function impUser(){
	    $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        $upload->exts      =     array('xls', 'xlsx');// 设置附件上传类
        $upload->rootPath  =     './Public/excel/'; // 设置附件上传根目录
        // 上传文件
		//var_dump($upload);die;
        $info   =   $upload->uploadOne($_FILES['excel']);
        $filename = './Public/excel/'.$info['savepath'].$info['savename'];
        $exts = $info['ext'];
     
        if(!$info)
		 {// 上传错误提示错误信息
              $this->error($upload->getError());
         }
		 else
		 {
			vendor('PHPExcel180.PHPExcel');
			//创建PHPExcel对象，注意，不能少了\
			$PHPExcel=new \PHPExcel();
			//如果excel文件后缀名为.xls，导入这个类
			if($exts == 'xls'){
				import("Org.Util.PHPExcel.Reader.Excel5");
				$PHPReader=new \PHPExcel_Reader_Excel5();
			}else if($exts == 'xlsx'){
				import("Org.Util.PHPExcel.Reader.Excel2007");
				$PHPReader=new \PHPExcel_Reader_Excel2007();
			}
			$datazz=array();
			$data=array();
			$data_sum=array();
	
	
			//载入文件
			$PHPExcel=$PHPReader->load($filename);
			//获取表中的第一个工作表，如果要获取第二个，把0改为1，依次类推
			$currentSheet=$PHPExcel->getSheet(0);
			//获取总列数
			//$allColumn=$currentSheet->getHighestColumn();
			$allColumn='V';
			//获取总行数
			$allRow=$currentSheet->getHighestRow();
			//循环获取表中的数据，$currentRow表示当前行，从哪行开始读取数据，索引值从0开始
			for($currentRow=1;$currentRow<=$allRow;$currentRow++){
				//从哪列开始，A表示第一列
				for($currentColumn='A';$currentColumn<=$allColumn;$currentColumn++){
					//数据坐标
					$address=$currentColumn.$currentRow;
					//读取到的数据，保存到数组$arr中
					$cell =$currentSheet->getCell($address)->getValue();
	
					if($cell instanceof PHPExcel_RichText){
						$cell  = $cell->__toString();
					}
					
					$data[$currentColumn]=$cell;
				}
				
				if($currentRow>1)
				{
					$data_sum[$currentRow]=$data;
					
				}
				
	            
			}  
			$product=M('product');
			$i=0;
			$str='';
			//var_dump($data_sum);die;
			if(!empty($data_sum))
			{  
				foreach($data_sum as $key=>$v)
				{
					if(!empty($v))
					{   
					
					    $data['sku']					=(string)$v['A'];
						$data['main_pic']				='A.jpg';
						$data['size_pic']				='B.jpg';
						$data['map_depot']				='1';
						//$data['price_type']				=(string)$v['C'];
						$data['brand']					=(string)$v['D'];
						$data['product_material']		=(string)$v['F'];
						$data['product_type']			=(string)$v['G'];
						
						$data['supplier']				=(string)$v['S'];
						$supplier = M('supplier')->field('for_short,buyer')->where(array('for_short'=>$data['supplier']))->find();
						if($supplier==NULL){		//如果不存该供应商关联，则供应商加(Not set)，同时，采购员也直接为(Not set)
							$data['supplier'] =(string)$data['supplier'].'(Not set)';
							$data['buyer']					='(Not set)';
						}else{
							$data['supplier'] 	=$supplier['for_short'];
							$data['buyer']		=$supplier['buyer'];
						}
						
						$data['addtime']				=(string)$v['T'];
						if($data['addtime']!=''){
							$data['addtime'] = $this->excelTime($v['T']).' 00:00:00';
							
						}else{
							$time = date('Y-m-d H:i:s',time());
							$data['addtime']				=$time;
						}
						//$data['addtime']				=$time;
						
						//$data['status'] 				= '1';
						$data['status'] 				= $_POST['status'] ?: 1;
						/*if($v['K']!=''){
							$time = $this->excelTime($v['K']).' 00:00:00';
						}else{
							$time = date('Y-m-d H:i:s',time());
						}*/
						
						//如果重量为空，则默认为0
						if(!empty($v['J'])){
							$data['weight']					=(string)$v['J'];
						}else{
							$data['weight']					='0';
						}
						
						//如果成本价为空，则默认为0
						if(!empty($v['K'])){
							$data['cost_price']				=(string)$v['K'];
						}else{
							$data['cost_price']				='0';
						}
						
						
						$control = M('price_control')->field('ali_lt,ali_gt,aliexpress,ioffer')->where(array('type'=>$data['price_type']))->find();
						if($control){
							if($control['ali_lt']==NULL || $control['ali_lt']==''){
								$data['ali_lt'] = '0';
							}else{
								$x = $data['cost_price'];
								$str1 = str_replace('x','$x',$control['ali_lt']);
								$str2 = str_replace('y1','$y1',$str1);
								$data['ali_lt']=eval("return $str2;");	
							}
							
							
							if($control['ali_gt']==NULL || $control['ali_gt']==''){
								$data['ali_gt'] = '0';
							}else{
								$x = $data['cost_price'];
								$str3 = str_replace('x','$x',$control['ali_gt']);
								$str4 = str_replace('y2','$y2',$str3);
								$data['ali_gt']=eval("return $str4;");
							}
							
							
							if($control['aliexpress']==NULL || $control['aliexpress']==''){
								$data['aliexpress'] = '0';
							}else{
								$x = $data['cost_price'];
								$str5 = str_replace('x','$x',$control['aliexpress']);
								$str6 = str_replace('y3','$y3',$str5);	
								$data['aliexpress']=eval("return $str6;");
							}
							
							
							if($control['ioffer']==NULL || $control['ioffer']==''){
								$data['ioffer'] = '0';
							}else{
								$x = $data['cost_price'];
								$str7 = str_replace('x','$x',$control['ioffer']);
								$str8 = str_replace('y4','$y4',$str7);
								$data['ioffer']=eval("return $str8;");
								
							}
			
						}else{
							$data['ali_lt']='0';
							$data['ali_gt']='0';
							$data['aliexpress']='0';
							$data['ioffer']='0';
						}
						//如果小於50件价为空，则默认为0
						/*if(!empty($v['J'])){
							$data['ali_lt']					=$v['J'];
						}else{
							$data['ali_lt']					='0';
						}
						//如果大於50件价为空，则默认为0
						if(!empty($v['K'])){
							$data['ali_gt']					=$v['K'];
						}else{
							$data['ali_gt']					='0';
						}
						//如果速賣通价为空，则默认为0
						if(!empty($v['L'])){
							$data['aliexpress']				=$v['L'];
						}else{
							$data['aliexpress']				='0';
						}
						//如果ioffer价为空，则默认为0
						if(!empty($v['M'])){
							$data['ioffer']					=$v['M'];
						}else{
							$data['ioffer']					='0';
						}
						*/
						
						//自主订货产品
                        $data['own_product'] = (string)$v['H'];
                        //虚拟产品
                        $data['fictitious_product'] = (string)$v['I'];
						
						//如果自定義描1述为空，则默认为空
						if(!empty($v['O'])){
							$data['custom_one']				=(string)$v['O'];
						}else{
							$data['custom_one']				='　';
						}
						//如果自定義描2述为空，则默认为空
						if(!empty($v['P'])){
							$data['custom_two']				=(string)$v['P'];
						}else{
							$data['custom_two']				='　';
						}
						//如果自定義描3述为空，则默认为空
						if(!empty($v['Q'])){
							$data['custom_three']			=(string)$v['Q'];
						}else{
							$data['custom_three']			='　';
						}
						//如果自定義描4述为空，则默认为空
						if(!empty($v['R'])){
							$data['custom_four']			=(string)$v['R'];
						}else{
							$data['custom_four']			='　';
						}

	
						
						
						
						
						
						
						
						//如果excel表中传递过来的值是否为默认款式 如果为是，则在数据库中添加为1  否则为2
						$default_styles					=$v['B'];
						if($default_styles=='是'){
							$data['default_styles']		=1;
						}else if(empty($default_styles) || $default_styles =='否'){
							$data['default_styles']		=2;
						}
						//如果excel表中传递过来的产品类型 如果为是，则在数据库中添加为1  否则为2
						/*$independent_product			=$v['C'];
						if($independent_product=='是'){
							$data['independent_product']=1;
						}else if(empty($independent_product) || $independent_product =='否'){
							$data['independent_product']=2;
						}
						*/
					

						
						//如果excel表中传递过来的值是否进入LOGO为是，则在数据库中添加为1  否则为2
						$logo							=$v['E'];
						if($logo=='是'){
							$data['logo']				=1;
						}else if(empty($logo) || $logo =='否'){
							$data['logo']				=2;
							
						}
						
						//根据供应商关联条购员
						/*$buyer		  =M('supplier')->field('buyer')->where(array('for_short'=>$v['J']))->find();
						$data['buyer']					= $buyer['buyer'];
						//根据产品类型关联价格公式
						$control = M('price_control')->field('ali_lt,ali_gt,aliexpress,ioffer')->where(array('type'=>$data['product_type']))->find();
						//根据成本价与价格公式，计算不同的指导价
						if($control){
							if($control['ali_lt']==NULL){
								$control['ali_lt'] = '0';
							}
							$x = $data['cost_price'];
							$str1 = str_replace('x','$x',$control['ali_lt']);
							$str2 = str_replace('y1','$y1',$str1);
							$data['ali_lt']=eval("return $str2;");	
							
							if($control['ali_gt']==NULL){
								$control['ali_gt'] = '0';
							}
							$str3 = str_replace('x','$x',$control['ali_gt']);
							$str4 = str_replace('y2','$y2',$str3);
							$data['ali_gt']=eval("return $str4;");
							
							if($control['aliexpress']==NULL){
								$control['aliexpress'] = '0';
							}
							$str5 = str_replace('x','$x',$control['aliexpress']);
							$str6 = str_replace('y3','$y3',$str5);	
							$data['aliexpress']=eval("return $str6;");
							
							if($control['ioffer']==NULL){
								$control['ioffer'] = '0';
							}
							$str7 = str_replace('x','$x',$control['ioffer']);
							$str8 = str_replace('y4','$y4',$str7);
							$data['ioffer']=eval("return $str8;");
			
						}else{
							$data['ali_lt']		 = 0;
							$data['ali_gt']		 = 0;
							$data['aliexpress']	 = 0;
							$data['ioffer']		 = 0;
						}*/


						//查询产品目录里是否已有该产品，如果有则修改，没有则删除
						//dump($data);exit;
						$check = M('product')->field('sku,addtime')->where(array('sku'=>$data['sku']))->find();
						if($check)
						{
							$data['addtime'] = $check['addtime'];
							$res = M('product')->where(array('sku'=>$data['sku']))->save($data);
							if($res!==false)
							{
								$i++;
							}
							else
							{
								$str.=$v['A']." 导入失败<br>";
							}
							
						}
						else
						{
							
							$res = M('product')->add($data);
							// 看price_type 是否存在
							//dump($data);exit;
							if($res)
							{
								$i++;
							}
							else
							{
								$str.=$v['A']."<br>";
							}
						}
						
						
					}
				}
				if(!empty($str))
				{   
				    $str.="其余导入成功";
					$prompt = "<div style='font-size:26px;'>以下产品导入不成功,请及时复制出以下产品,检查后编辑再重新导入！</div><br/>";
					echo $prompt.$str;die;
				}
				else
				{
					$this->success('导入成功');
				}
				
				
			}
			else
			{
				$this->error('没有数据');
			}
			
         }
     
    }
	
	function showAllProperties2(){
         var_dump(get_object_vars($this));
     }
	 /**
	  * @author 脚本之家
	  * @date 2013-6-21
	  * @todo 将对象转换成数组
	  * @param unknown_type $obj
	  * @return unknown
	  */
	 function object_to_array($obj){
	  $_arr = is_object($obj) ? get_object_vars($obj) :$obj;
	  
	  foreach ($_arr as $key=>$val){
	   $val = (is_array($val) || is_object($val)) ? $this->object_to_array($val):$val;
	   $arr[$key] = $val;
	  }
	  return $arr;
	 }
	//php导入excel时间格式的转化
	function excelTime($days, $time=false){
		if(is_numeric($days)){
			//based on 1900-1-1
			$jd = GregorianToJD(1, 1, 1970);
			$gregorian = JDToGregorian($jd+intval($days)-25569);
			$myDate = explode('/',$gregorian);
			$myDateStr = str_pad($myDate[2],4,'0', STR_PAD_LEFT)
					."-".str_pad($myDate[0],2,'0', STR_PAD_LEFT)
					."-".str_pad($myDate[1],2,'0', STR_PAD_LEFT)
					.($time?" 00:00:00":'');
			return $myDateStr;
		}
		return $days;
	}



	//自定义导出批量推荐表
	public function customProduct(){
		if($_POST){
			$type = I('type','','htmlspecialchars');
			$info = I('info','','htmlspecialchars');
			$info_list=explode("\n",trim($info,"\n"));
			foreach($info_list as $ka=>$va){
				$string = trim($va);
				if($string==''){
					unset($info_list[$ka]);
				}
			}
			foreach(array_merge($info_list) as $k=>$v){
				$res 	= explode("	",trim($v,"	"));
				$is_arr = count($res);
				if($is_arr==1){
					$data[$k] = M('product')->field('sku,ali_lt,ali_gt,aliexpress,ioffer')->where(array('sku'=>trim($v)))->find();
					if($data[$k]==NULL){
						$error .= trim($v).'<br/>';
					}
					if($data[$k]['sku']==NULL){unset($data[$k]);}
					$data = array_merge($data);
				}else if($is_arr==2){
					$data[$k] = M('product')->field('sku,ali_lt,ali_gt,aliexpress,ioffer')->where(array('sku'=>trim($res['0'])))->find();
					$data[$k]['stock']	=	$res['1'];
					if($data[$k]['sku']==NULL){
						$error .= trim($res['0']).'<br/>';
					}
					if($data[$k]['sku']==NULL){unset($data[$k]);}
					$data = array_merge($data);
					
				}	
			}
			$count	=	count(array_merge($data));
			if($count<1 && $data['0']==NULL){$this->error("推荐产品不能为空");die;}

			if($is_arr==1){
				// 导出Exl
		        import("Org.Util.PHPExcel");
		        import("Org.Util.PHPExcel.Worksheet.Drawing");
		        import("Org.Util.PHPExcel.Writer.Excel2007");
				import("Org.Util.PHPExcel.Style.NumberFormat");
				import("Org.Util.PHPExcel.Style.Alignment");
				import("Org.Util.PHPExcel.Style.Color");
				
				import("Org.Util.PHPExcel.Style.Border");
		        $objPHPExcel = new \PHPExcel();
		        $objWriter = new \PHPExcel_Writer_Excel2007($objPHPExcel);
		    
		        $objActSheet = $objPHPExcel->getActiveSheet();
		        
		        // 水平居中（位置很重要，建议在最初始位置）
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        
		        
		        // 垂直居中
		        $objPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
		        $objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
		        $objPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
		        $objPHPExcel->getActiveSheet()->getStyle('E')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
		        $objPHPExcel->getActiveSheet()->getStyle('F')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
		        $objPHPExcel->getActiveSheet()->getStyle('G')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
		        
				//合并列单元
				//设置宽度
				// 设置个表格宽度
		        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(1);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(1);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(25);
				
		        $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(1);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(25);
				
				
	            $objDrawing[1] = new \PHPExcel_Worksheet_Drawing();
	            $objDrawing[1]->setPath('Public/img/logo.png');
	            // 设置宽度高度
	            $objDrawing[1]->setHeight(100);//照片高度
	            $objDrawing[1]->setWidth('120'); //照片宽度
	            /*设置图片要插入的单元格*/
	            $objDrawing[1]->setCoordinates('A1');
				
	            // 图片偏移距离
	            $objDrawing[1]->setOffsetX(30);
	            $objDrawing[1]->setOffsetY(0);
	            $objDrawing[1]->setWorksheet($objPHPExcel->getActiveSheet());
				
				
				$objPHPExcel->getActiveSheet()->mergeCells('A1:H1');
				
	       		$objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyle('A1')->applyFromArray(

		            array(

		                'font' => array (

		                    'bold' => true,
							'size'=>'26'

		                ),

	            	)

		        );
				$objActSheet->setCellValue('A1', 'Touch Love Jewelry Co., Ltd.');
				
	            $objActSheet->getRowDimension(1)->setRowHeight(45);
				
				$objPHPExcel->getActiveSheet()->mergeCells('A2:H2');
				$objActSheet->setCellValue('A2', 'Add: R801 Tairong business building, No.63 Xizeng Road, GuangZhou, China');
	            
				
				$objPHPExcel->getActiveSheet()->mergeCells('A3:H3');
				$objActSheet->setCellValue('A3', 'Email:sale@touch-love-jewelry.com  TEL:+86-20-81537159');
				$objPHPExcel->getActiveSheet()->getStyle('A4')->applyFromArray(

		            array(

		                'font' => array (

		                    'bold' => true,
							'size'=>'14'

		                ),

		            )

		        );
				$objPHPExcel->getActiveSheet()->mergeCells('A4:H4');
				$objActSheet->setCellValue('A4', 'Website: http://touchlove.en.alibaba.com');
				
				$objPHPExcel->getActiveSheet()->mergeCells('A5:H5');
				$objPHPExcel->setActiveSheetIndex(0)->getStyle('A5')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
	       	 	$objPHPExcel->getActiveSheet()->getStyle('A5')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_BOTTOM);
				$objActSheet->setCellValue('A5', "Welcome to view our product. If you like any product, please send me the Code No. and Quantity  Enjoy your shopping");
				$objPHPExcel->setActiveSheetIndex(0)->getStyle('A5')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
				$objActSheet->getRowDimension(5)->setRowHeight(20);
					
					
					
				$objPHPExcel->getActiveSheet()->getStyle('A6')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
				
				$objActSheet->setCellValue('A6', '1');
				$objPHPExcel->getActiveSheet()->mergeCells('B6:H6');
				$objActSheet->setCellValue('B6', 'Based on FOB China price');	
				$objPHPExcel->setActiveSheetIndex(0)->getStyle('B6')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);	
				$objActSheet->setCellValue('A7', '2');
				$objPHPExcel->getActiveSheet()->mergeCells('B7:H7');
				$objActSheet->setCellValue('B7', 'Mini Order 3 pcs / model');
				
				$objPHPExcel->setActiveSheetIndex(0)->getStyle('B7')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
					
				$count = ((count($data)%4));	//一共需要几行
				$countAll = count($data);				//一共有几条数据
				$sum_count = (ceil(sizeof($data)/4))*3+8;
				//var_dump($data);die;
				foreach($data as $key=>$value){ 
					$i=8;
					$i+=$key;
					//echo $i;
					if(is_int($i/4)){
						$_SESSION['y']='B';
						$_SESSION['Photo']=$key/4*3+8;
						$_SESSION['sku']=$key/4*3+9;
						$_SESSION['price']=$key/4*3+10;
						$objActSheet->setCellValue('A'.$_SESSION['Photo'], 'Photo');   
						
						$objActSheet->getRowDimension($_SESSION['Photo'])->setRowHeight(120); 
						$objActSheet->setCellValue('A'.$_SESSION['sku'], 'Code No.');  
						
						$objActSheet->getRowDimension($_SESSION['sku'])->setRowHeight(20); 
						$objActSheet->setCellValue('A'.$_SESSION['price'], 'Unit price'); 
						
						$objActSheet->getRowDimension($_SESSION['price'])->setRowHeight(40); 
					}elseif(is_int(($i+3)/4)){
						$_SESSION['y']='D';	
					}elseif(is_int(($i+2)/4)){
						$_SESSION['y']='F';
					}else{
						$_SESSION['y']='H';
					}
					if(is_int($key/4)){
						$_SESSION['i']=$i;
					}
				
					$dir = "public/images/".$value['sku']; // 文件夹的名称
					$file = array();
					if (is_dir($dir)){
					  if ($dh = opendir($dir)){
						while (($file[] = readdir($dh)) !== false){
						}
						closedir($dh);
					  }
					}
					
					if( in_array("A.jpg",$file) || in_array("A.jpeg",$file) || in_array("A.png",$file) || in_array("A.gif",$file) || in_array("A.JPG",$file) || in_array("A.JPEG",$file) || in_array("A.PNG",$file) || in_array("A.GIF",$file)){
					  	$objDrawing[$i] = new \PHPExcel_Worksheet_Drawing();
						$path = $value['sku'].'/A.jpg';
						$objDrawing[$i]->setPath('Public/images/'.$path);
						// 设置宽度高度
						$objDrawing[$i]->setHeight(60);//照片高度
						$objDrawing[$i]->setWidth(160); //照片宽度
						/*设置图片要插入的单元格*/
						$objDrawing[$i]->setCoordinates($_SESSION['y'].$_SESSION['Photo']);
						// 图片偏移距离
						$objDrawing[$i]->setOffsetX(5);
						$objDrawing[$i]->setOffsetY(5);
						$objDrawing[$i]->setWorksheet($objPHPExcel->getActiveSheet());
						
						$objActSheet->getRowDimension($_SESSION['Photo'])->setRowHeight(130); 
							
					}else{
						$objActSheet->setCellValue($_SESSION['y'].$_SESSION['Photo'], '图片丢失'); 
						
        				$objPHPExcel->setActiveSheetIndex(0)->getStyle($_SESSION['y'].$_SESSION['Photo'])->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
						
        				$objPHPExcel->getActiveSheet()->getStyle($_SESSION['y'].$_SESSION['Photo'])->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
						
					}
					
						
					$objActSheet->setCellValue($_SESSION['y'].$_SESSION['sku'], $value['sku']);   
					
		 			$objPHPExcel->setActiveSheetIndex(0)->getStyle($_SESSION['y'].$_SESSION['sku'])->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);       
		 			$objPHPExcel->getActiveSheet()->getStyle($_SESSION['y'].$_SESSION['sku'])->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
		 
					$objActSheet->getRowDimension($_SESSION['sku'])->setRowHeight(20);  
					if($type=='1'){
						$price 	=	$value['ali_lt'];
					}else if($type=='2'){
						$price 	=	$value['ali_gt'];
					}else if($type=='3'){
						$price 	=	$value['aliexpress'];
					}else if($type=='4'){
						$price 	=	$value['ioffer'];
					}
					$objActSheet->setCellValue($_SESSION['y'].$_SESSION['price'], 'US$'.$price);
					
					
		 			$objPHPExcel->setActiveSheetIndex(0)->getStyle($_SESSION['y'].$_SESSION['price'])->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);       
		 			$objPHPExcel->getActiveSheet()->getStyle($_SESSION['y'].$_SESSION['price'])->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
					
					$objActSheet->getRowDimension($_SESSION['price'])->setRowHeight(40); 
				}
		        // $fileName = '新品推荐表';
		        // $date = date("Y-m-d",time());
		        // $fileName .= "_{$date}.xls";

		        // $fileName = iconv("utf-8", "gb2312", $fileName);
		        // //重命名表
		        // // $objPHPExcel->getActiveSheet()->setTitle('test');
		        // //设置活动单指数到第一个表,所以Excel打开这是第一个表
		        // $objPHPExcel->setActiveSheetIndex(0);
		        // header('Content-Type: application/vnd.ms-excel');
		        // header("Content-Disposition: attachment;filename=\"$fileName\"");	//图片另存为
		        // header('Cache-Control: max-age=0');

		        // $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
		        // $objWriter->save('php://output'); //文件通过浏览器下载
		        // END
			}else if($is_arr==2){
				// 导出Exl
		        import("Org.Util.PHPExcel");
		        import("Org.Util.PHPExcel.Worksheet.Drawing");
		        import("Org.Util.PHPExcel.Writer.Excel2007");
				import("Org.Util.PHPExcel.Style.NumberFormat");
				import("Org.Util.PHPExcel.Style.Alignment");
				import("Org.Util.PHPExcel.Style.Color");
				
				import("Org.Util.PHPExcel.Style.Border");
		        $objPHPExcel = new \PHPExcel();
		        $objWriter = new \PHPExcel_Writer_Excel2007($objPHPExcel);
		    
		        $objActSheet = $objPHPExcel->getActiveSheet();
		        
		        // 水平居中（位置很重要，建议在最初始位置）
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		        
		        
		        // 垂直居中
		        $objPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
		        $objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
		        $objPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
		        $objPHPExcel->getActiveSheet()->getStyle('E')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
		        $objPHPExcel->getActiveSheet()->getStyle('F')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
		        $objPHPExcel->getActiveSheet()->getStyle('G')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
		        
				//合并列单元
				//设置宽度
				// 设置个表格宽度
		        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(1);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(1);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(25);
				
		        $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(1);
		        $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(25);
				
				
	            $objDrawing[1] = new \PHPExcel_Worksheet_Drawing();
	            $objDrawing[1]->setPath('Public/img/logo.png');
	            // 设置宽度高度
	            $objDrawing[1]->setHeight(100);//照片高度
	            $objDrawing[1]->setWidth('120'); //照片宽度
	            /*设置图片要插入的单元格*/
	            $objDrawing[1]->setCoordinates('A1');
				
	            // 图片偏移距离
	            $objDrawing[1]->setOffsetX(30);
	            $objDrawing[1]->setOffsetY(0);
	            $objDrawing[1]->setWorksheet($objPHPExcel->getActiveSheet());
				
				
				$objPHPExcel->getActiveSheet()->mergeCells('A1:H1');
				
	       		$objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyle('A1')->applyFromArray(

		            array(

		                'font' => array (

		                    'bold' => true,
							'size'=>'26'

		                ),

		            )

		        );
				$objActSheet->setCellValue('A1', 'Touch Love Jewelry Co., Ltd.');
				
	            $objActSheet->getRowDimension(1)->setRowHeight(45);
				
				$objPHPExcel->getActiveSheet()->mergeCells('A2:H2');
				$objActSheet->setCellValue('A2', 'Add: R801 Tairong business building, No.63 Xizeng Road, GuangZhou, China');
	            
				
				$objPHPExcel->getActiveSheet()->mergeCells('A3:H3');
				$objActSheet->setCellValue('A3', 'Email:sale@touch-love-jewelry.com  TEL:+86-20-81537159');
				$objPHPExcel->getActiveSheet()->getStyle('A4')->applyFromArray(

		            array(

		                'font' => array (

		                    'bold' => true,
							'size'=>'14'

		                ),

		            )

		        );
				$objPHPExcel->getActiveSheet()->mergeCells('A4:H4');
				$objActSheet->setCellValue('A4', 'Website: http://touchlove.en.alibaba.com');
				
				$objPHPExcel->getActiveSheet()->mergeCells('A5:H5');
				$objPHPExcel->setActiveSheetIndex(0)->getStyle('A5')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
	       	 	$objPHPExcel->getActiveSheet()->getStyle('A5')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_BOTTOM);
				$objActSheet->setCellValue('A5', "Welcome to view our product. If you like any product, please send me the Code No. and Quantity  Enjoy your shopping");
				$objPHPExcel->setActiveSheetIndex(0)->getStyle('A5')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
				$objActSheet->getRowDimension(5)->setRowHeight(20);
					
					
					
				$objPHPExcel->getActiveSheet()->getStyle('A6')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
				
				$objActSheet->setCellValue('A6', '1');
				$objPHPExcel->getActiveSheet()->mergeCells('B6:H6');
				$objActSheet->setCellValue('B6', 'Based on FOB China price');	
				$objPHPExcel->setActiveSheetIndex(0)->getStyle('B6')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);	
				$objActSheet->setCellValue('A7', '2');
				$objPHPExcel->getActiveSheet()->mergeCells('B7:H7');
				$objActSheet->setCellValue('B7', 'Mini Order 3 pcs / model');
				
				$objPHPExcel->setActiveSheetIndex(0)->getStyle('B7')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
					
				$count = ((count($data)%4));	//一共需要几行
				$countAll = count($data);				//一共有几条数据
				$sum_count = (ceil(sizeof($data)/4))*4+8;
				//var_dump($data);die;
				foreach($data as $key=>$value){ 
					$i=8;
					$i+=$key;
					
					if(is_int($i/4)){
						$_SESSION['y']='B';
						$_SESSION['Photo']=$key/4*4+8;
						$_SESSION['sku']=$key/4*4+9;
						$_SESSION['price']=$key/4*4+10;
						$_SESSION['stock']=$key/4*4+11;
						$objActSheet->setCellValue('A'.$_SESSION['Photo'], 'Photo');   
						
						$objActSheet->getRowDimension($_SESSION['Photo'])->setRowHeight(120); 
						$objActSheet->setCellValue('A'.$_SESSION['sku'], 'Code No.');  
						
						$objActSheet->getRowDimension($_SESSION['sku'])->setRowHeight(20); 
						$objActSheet->setCellValue('A'.$_SESSION['price'], 'Unit price'); 
						
						$objActSheet->getRowDimension($_SESSION['price'])->setRowHeight(40); 

						$objActSheet->setCellValue('A'.$_SESSION['stock'], 'Stock'); 
						
						$objActSheet->getRowDimension($_SESSION['stock'])->setRowHeight(40); 
					}elseif(is_int(($i+3)/4)){
						$_SESSION['y']='D';	
					}elseif(is_int(($i+2)/4)){
						$_SESSION['y']='F';
					}else{
						$_SESSION['y']='H';
					}
					if(is_int($key/4)){
						$_SESSION['i']=$i;
					}
				
					$dir = "public/images/".$value['sku']; // 文件夹的名称
					$file = array();
					if (is_dir($dir)){
					  if ($dh = opendir($dir)){
						while (($file[] = readdir($dh)) !== false){
						}
						closedir($dh);
					  }
					}
					
					
					if( in_array("A.jpg",$file) || in_array("A.jpeg",$file) || in_array("A.png",$file) || in_array("A.gif",$file) || in_array("A.JPG",$file) || in_array("A.JPEG",$file) || in_array("A.PNG",$file) || in_array("A.GIF",$file)){
					  	$objDrawing[$i] = new \PHPExcel_Worksheet_Drawing();
						$path = $value['sku'].'/A.jpg';
						
					
						
						$objDrawing[$i]->setPath('Public/images/'.$path);
						// 设置宽度高度
						$objDrawing[$i]->setHeight(60);//照片高度
						$objDrawing[$i]->setWidth(160); //照片宽度
						/*设置图片要插入的单元格*/
						$objDrawing[$i]->setCoordinates($_SESSION['y'].$_SESSION['Photo']);
						// 图片偏移距离
						$objDrawing[$i]->setOffsetX(5);
						$objDrawing[$i]->setOffsetY(5);
						$objDrawing[$i]->setWorksheet($objPHPExcel->getActiveSheet());
						
						$objActSheet->getRowDimension($_SESSION['Photo'])->setRowHeight(130); 
						
					}else{
						$objActSheet->setCellValue($_SESSION['y'].$_SESSION['Photo'], '图片丢失'); 
						
        				$objPHPExcel->setActiveSheetIndex(0)->getStyle($_SESSION['y'].$_SESSION['Photo'])->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
						
        				$objPHPExcel->getActiveSheet()->getStyle($_SESSION['y'].$_SESSION['Photo'])->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
						
				}
						$objActSheet->setCellValue($_SESSION['y'].$_SESSION['sku'], $value['sku']);   
						
			 			$objPHPExcel->setActiveSheetIndex(0)->getStyle($_SESSION['y'].$_SESSION['sku'])->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);       
			 			$objPHPExcel->getActiveSheet()->getStyle($_SESSION['y'].$_SESSION['sku'])->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
			 
						$objActSheet->getRowDimension($_SESSION['sku'])->setRowHeight(20);  
						if($type=='1'){
							$price 	=	$value['ali_lt'];
						}else if($type=='2'){
							$price 	=	$value['ali_gt'];
						}else if($type=='3'){
							$price 	=	$value['aliexpress'];
						}else if($type=='4'){
							$price 	=	$value['ioffer'];
						}
						$objActSheet->setCellValue($_SESSION['y'].$_SESSION['price'], 'US$'.$price);

							
				 		$objPHPExcel->setActiveSheetIndex(0)->getStyle($_SESSION['y'].$_SESSION['price'])->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);       
				 		$objPHPExcel->getActiveSheet()->getStyle($_SESSION['y'].$_SESSION['price'])->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);

						
						$objActSheet->getRowDimension($_SESSION['price'])->setRowHeight(40); 
						$objActSheet->setCellValue($_SESSION['y'].$_SESSION['stock'], $value['stock']);
						$objPHPExcel->getActiveSheet()->getStyle($_SESSION['y'].$_SESSION['stock'])->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
					}
				}

				if(!empty($error)){
					$prompt = "<div style='font-size:26px;'>以下产品不存在,检查后编辑再重新导出！</div><br/>";
					echo $prompt.$error;die;
		        }


		        /*****    


											输出账号信息 开始

		        ***/

				$k=$_SESSION['price'];
				$objPHPExcel->getActiveSheet()->mergeCells('A'.($k+14).':G'.($k+14));
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('A'.($k+14))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objActSheet->setCellValue('A'.($k+14), 'Account details for orders:');  
			
			$objPHPExcel->getActiveSheet()->getStyle('A'.($k+14))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			
			$objPHPExcel->getActiveSheet()->mergeCells('A'.($k+15).':G'.($k+15));
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('A'.($k+15))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objActSheet->setCellValue('A'.($k+15), 'T/T: ($30 handle fee is needed for each payment)');  
			
			
			
			
			
			
			$objPHPExcel->getActiveSheet()->mergeCells('A'.($k+16).':A'.($k+21));
			$objPHPExcel->getActiveSheet()->getStyle('A'.($k+16))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objActSheet->setCellValue('A'.($k+16), 'Bank Details');
			
			
			$objActSheet->setCellValue('B'.($k+16), 'Company Name:');
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('B'.($k+16))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->getStyle('B'.($k+16))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'11'

                ),

            )

        );
			$objPHPExcel->getActiveSheet()->mergeCells('C'.($k+16).':G'.($k+16));
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('C'.($k+16))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->getStyle('C'.($k+16))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objActSheet->setCellValue('C'.($k+16), 'TOUCH LOVE JEWELRY CO., LIMITED');
			
			
			
			$objActSheet->setCellValue('B'.($k+17), 'Beneficiary Bank:');
			$objPHPExcel->getActiveSheet()->getStyle('B'.($k+17))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('B'.($k+17))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('C'.($k+17))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->getStyle('C'.($k+17))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objPHPExcel->getActiveSheet()->mergeCells('C'.($k+17).':G'.($k+17));
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('C'.($k+18))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objActSheet->setCellValue('C'.($k+17), 'HSBC Hong Kong');
			
			$objPHPExcel->getActiveSheet()->getStyle('B'.($k+18))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objActSheet->setCellValue('B'.($k+18), 'Branch code');
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('B'.($k+18))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->getStyle('C'.($k+18))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('C'.($k+19))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->mergeCells('C'.($k+18).':G'.($k+18));
			$objActSheet->setCellValue('C'.($k+18), " 004");
			
			
			$objPHPExcel->getActiveSheet()->getStyle('B'.($k+19))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objActSheet->setCellValue('B'.($k+19), 'Bank Account No:');
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('B'.($k+19))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('C'.($k+19))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->getStyle('C'.($k+19))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objPHPExcel->getActiveSheet()->mergeCells('C'.($k+19).':G'.($k+19));
			$objActSheet->setCellValue('C'.($k+19), '817-810799-838');
			
			
			
			$objPHPExcel->getActiveSheet()->getStyle('B'.($k+20))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			
			$objActSheet->setCellValue('B'.($k+20), 'Bank Address:');
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('B'.($k+20))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->getStyle('C'.($k+20))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
		 	
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('C'.($k+20))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->mergeCells('C'.($k+20).':G'.($k+20));
			$objActSheet->setCellValue('C'.($k+20), "1 Queen's Road Central, HongKong");
			
			
			$objPHPExcel->getActiveSheet()->getStyle('B'.($k+21))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objActSheet->setCellValue('B'.($k+21), 'Swift BIC:');
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('B'.($k+21))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->getStyle('C'.($k+21))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('C'.($k+21))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->mergeCells('C'.($k+21).':G'.($k+21));
			$objPHPExcel->getActiveSheet()->getStyle('C'.($k+21))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objActSheet->setCellValue('C'.($k+21), 'HSBCHKHHHKH');
			
			
			$objPHPExcel->getActiveSheet()->mergeCells('A'.($k+22).':G'.($k+22));
			$objActSheet->setCellValue('A'.($k+22), '');
			
			
			
			
			$objActSheet->setCellValue('A'.($k+23), 'Western Union');
			$objPHPExcel->getActiveSheet()->mergeCells('B'.($k+23).':G'.($k+23));
			$objActSheet->setCellValue('B'.($k+23), 'XIAOYAN   CHEN  ( First Name:XIAOYAN, Last Name: CHEN, Received City : GuangZhou, China)');
			
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('B'.($k+23))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			
			$objPHPExcel->getActiveSheet()->getStyle('A'.($k+23))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'11'

                ),

            )

        );
		
		$objPHPExcel->getActiveSheet()->getStyle('B'.($k+23))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'14'

                ),

            )

        );

				/*  结束输出账号信息  */

				$fileName = '新品推荐表';
		        $date = date("Y-m-d",time());
		        $fileName .= "_{$date}.xls";

		        $fileName = iconv("utf-8", "gb2312", $fileName);
		        //重命名表
		        // $objPHPExcel->getActiveSheet()->setTitle('test');
		        //设置活动单指数到第一个表,所以Excel打开这是第一个表
		        $objPHPExcel->setActiveSheetIndex(0);
		        header('Content-Type: application/vnd.ms-excel');
		        header("Content-Disposition: attachment;filename=\"$fileName\"");	//图片另存为
		        header('Cache-Control: max-age=0');

		        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
		        $objWriter->save('php://output'); //文件通过浏览器下载
		        // END
		        
		}
		$this->display();	
	}

	//导出选择的产品
	public function daochu_excel(){
		$name = $_SESSION['user'];
		$acc_type = M('account')->field('cost_price,supplier')->where(array('username'=>$name))->find();
		$ids = I('get.tids','','htmlspecialchars');
		$id_list = explode(',',trim($ids,','));
		foreach($id_list as $key=>$val){
			if($acc_type['supplier'] =='1'){
			$data[$key] = M('product')->field('sku,default_styles,independent_product,brand,logo,product_material,product_type,weight,cost_price,supplier,addtime')->where(array('id'=>$val))->find();
			}else{
				$data[$key] = M('product')->field('sku,default_styles,independent_product,brand,logo,product_material,product_type,weight,cost_price,addtime')->where(array('id'=>$val))->find();
			}
			
		}
		foreach($data as $key=>$val){
			if($val['default_styles']=='1'){
				$data[$key]['default_styles']='是';
			}else{
				$data[$key]['default_styles']='否';
			}
			
			if($val['independent_product']=='1'){
				$data[$key]['independent_product']='是';
			}else{
				$data[$key]['independent_product']='否';
			}
			
			if($val['independent_product']==''){
				$data[$key]['independent_product']='';
			}
			if($val['logo']=='1'){
				$data[$key]['logo']='是';
			}else{
				$data[$key]['logo']='否';
			}
		}
		$filename = "excel";
		if($acc_type['supplier'] =='1'){
			$title = array('SKU','主图','尺寸图','进入图库','默认款式','线上产品','品牌','LOGO','产品材质','产品类型','重量','阿里国际','','成本价','供应商','创建时间');
			}else{
				$title = array('SKU','默认款式','线上产品','品牌','LOGO','产品材质','产品类型','重量','成本价','创建时间');
			}
		
		$res = $this->exportexcel($data,$title,$filename);
	}
	
	
	
	//导出选择的产品   导出部份属性
	/*public function daochu_excel(){
		$name = $_SESSION['user'];
		$acc_type = M('account')->field('cost_price,supplier')->where(array('username'=>$name))->find();
		$ids = I('get.tids','','htmlspecialchars');
		$id_list = explode(',',trim($ids,','));
		foreach($id_list as $key=>$val){
			if($acc_type['supplier'] =='1'){
			$data[$key] = M('product')->field('sku,default_styles,independent_product,brand,logo,product_material,product_type,weight,cost_price,supplier,addtime')->where(array('id'=>$val))->find();
			}else{
				$data[$key] = M('product')->field('sku,default_styles,independent_product,brand,logo,product_material,product_type,weight,cost_price,addtime')->where(array('id'=>$val))->find();
			}
			
		}
		foreach($data as $key=>$val){
			if($val['default_styles']=='1'){
				$data[$key]['default_styles']='是';
			}else{
				$data[$key]['default_styles']='否';
			}
			
			if($val['independent_product']=='1'){
				$data[$key]['independent_product']='是';
			}else{
				$data[$key]['independent_product']='否';
			}
			
			if($val['independent_product']==''){
				$data[$key]['independent_product']='';
			}
			if($val['logo']=='1'){
				$data[$key]['logo']='是';
			}else{
				$data[$key]['logo']='否';
			}
		}
		$filename = "excel";
		if($acc_type['supplier'] =='1'){
			$title = array('SKU','默认款式','线上产品','品牌','LOGO','产品材质','产品类型','重量','成本价','供应商','创建时间');
			}else{
				$title = array('SKU','默认款式','线上产品','品牌','LOGO','产品材质','产品类型','重量','成本价','创建时间');
			}
		
		$res = $this->exportexcel($data,$title,$filename);
	}*/
	
	
	//导出满足条件的产品  
	//调整过 excel表的列 @falcon
	public function search_daochu(){
		
		$sku 					= I('get.sku','','htmlspecialchars');
		$default_styles 		= I('get.default_styles','','htmlspecialchars');
		$independent_product 	= I('get.independent_product','','htmlspecialchars');
		$brand 					= I('get.brand','','htmlspecialchars');
		$logo 					= I('get.logo','','htmlspecialchars');
		$product_material 		= I('get.product_material','','htmlspecialchars');
		$product_type 			= I('get.product_type','','htmlspecialchars');
		$weight_before 			= I('get.weight_before','','htmlspecialchars');
		$weight_after			= I('get.weight_after','','htmlspecialchars');
		$cost_price_before 		= I('get.cost_price_before','','htmlspecialchars');
		$cost_price_after		= I('get.cost_price_after','','htmlspecialchars');
		$ali_lt_start 			= I('get.ali_lt_start','','htmlspecialchars');
		$ali_lt_end 			= I('get.ali_lt_end','','htmlspecialchars');
		$ali_gt_start			= I('get.ali_gt_start','','htmlspecialchars');
		$ali_gt_end 			= I('get.ali_gt_end','','htmlspecialchars');
		$aliexpress_start 		= I('get.aliexpress_start','','htmlspecialchars');
		$aliexpress_end 		= I('get.aliexpress_end','','htmlspecialchars');
		$ioffer_start 			= I('get.ioffer_start','','htmlspecialchars');
		$ioffer_end 			= I('get.ioffer_end','','htmlspecialchars');
		$custom_one 			= I('get.custom_one','','htmlspecialchars');
		$custom_two 			= I('get.custom_two','','htmlspecialchars');
		$custom_three			= I('get.custom_three','','htmlspecialchars');
		$custom_four 			= I('get.custom_four','','htmlspecialchars');
		$supplier 				= I('get.supplier','','htmlspecialchars');
		$buyer 					= I('get.buyer','','htmlspecialchars');
		$starttime 				= I('get.starttime','','htmlspecialchars');
		$endtime 				= I('get.endtime','','htmlspecialchars');
		
		$res = D('product')->searchListAll($sku,$default_styles,$independent_product,$brand,$logo,$product_material,$product_type,$weight_before,$weight_after,$cost_price_before,$cost_price_after,$ali_lt_start,$ali_lt_end,$ali_gt_start,$ali_gt_end,$aliexpress_start,$aliexpress_end,$ioffer_start,$ioffer_end,$custom_one,$custom_two,$custom_three,$custom_four,$supplier,$buyer,$starttime,$endtime);

		$id_list = $res['product_list'];
		$name = $_SESSION['user'];
		$acc_type = M('account')->field('cost_price,supplier')->where(array('username'=>$name))->find();
		
		$custom = M('custom')->where(array('id'=>'1'))->find();
		
		foreach($id_list as $key=>$val){
			if($acc_type['supplier'] =='1'){
			$data[$key] = M('product')->field('sku,default_styles,independent_product,brand,logo,product_material,product_type,weight,cost_price,ali_lt,ali_gt,aliexpress,	ioffer,custom_one,custom_two,custom_three,custom_four,supplier,buyer,addtime')->where(array('id'=>$val['id']))->find();
			}else{
				$data[$key] = M('product')->field('sku,default_styles,independent_product,brand,logo,product_material,product_type,weight,cost_price,ali_lt,ali_gt,aliexpress,	ioffer,custom_one,custom_two,custom_three,custom_four,buyer,addtime')->where(array('id'=>$val['id']))->find();
			}
			
			
		}
		
		foreach($data as $key=>$val){
			if($val['default_styles']=='1'){
				$data[$key]['default_styles']='是';
			}else{
				$data[$key]['default_styles']='否';
			}
			
			if($val['independent_product']=='1'){
				$data[$key]['independent_product']='是';
			}else{
				$data[$key]['independent_product']='否';
			}
			
			if($val['logo']=='1'){
				$data[$key]['logo']='是';
			}else{
				$data[$key]['logo']='否';
			}
			
			if($val['independent_product']==''){
				$data[$key]['independent_product']='';
			}
		}
		error_reporting(E_ALL);
        date_default_timezone_set('PRC');
		  
		import("Org.Util.PHPExcel");
        import("Org.Util.PHPExcel.Worksheet.Drawing");
        import("Org.Util.PHPExcel.Writer.Excel2007");
		import("Org.Util.PHPExcel.Style.NumberFormat");
		import("Org.Util.PHPExcel.Style.Alignment");
		import("Org.Util.PHPExcel.Style.Color");

		import("Org.Util.PHPExcel.Style.Border");
		//设定缓存模式为经gzip压缩后存入cache（还有多种方式请百度）  
		$cacheMethod = \PHPExcel_CachedObjectStorageFactory::cache_in_memory_gzip; 
		$cacheSettings = array();  
		\PHPExcel_Settings::setCacheStorageMethod($cacheMethod,$cacheSettings);  

        $objPHPExcel = new \PHPExcel();
        $objWriter = new \PHPExcel_Writer_Excel2007($objPHPExcel);
    
        $objActSheet = $objPHPExcel->getActiveSheet();
		
		if($acc_type['supplier'] =='1'){
			$objActSheet ->setCellValue('A1', 'SKU');       
			$objActSheet ->setCellValue('B1', '默认款式');
			//$objActSheet ->setCellValue('C1', '线上产品');
			$objActSheet ->setCellValue('C1', "价格类型");
			$objActSheet ->setCellValue('D1', "品牌");    
			$objActSheet ->setCellValue('E1', "LOGO");
			$objActSheet ->setCellValue('F1', "产品材质");
			$objActSheet ->setCellValue('G1', "产品类型"); 
			$objActSheet ->setCellValue('H1', "自主订货产品");
			$objActSheet ->setCellValue('I1', "虚拟产品");   
			$objActSheet ->setCellValue('J1', "重量单位：g");
			$objActSheet ->setCellValue('K1', '成本价单位：￥');
			$objActSheet ->setCellValue('L1', "批发散货价单位：$");    
			$objActSheet ->setCellValue('M1', "批发订货价单位：$");
			$objActSheet ->setCellValue('N1', "零售价单位：$");
			//$objActSheet ->setCellValue('M1', "IOFFER指导价单位：$");    
			$objActSheet ->setCellValue('O1', $custom['one']);
			$objActSheet ->setCellValue('P1', $custom['two']);
			$objActSheet ->setCellValue('Q1', $custom['three']);    
			$objActSheet ->setCellValue('R1', $custom['four']);
			$objActSheet ->setCellValue('S1', "供应商");  //如果 $acc_type['supplier'] =='1' 才显示， 否则不显示
			$objActSheet ->setCellValue('T1', "采购员");
			$objActSheet ->setCellValue('U1', "产品创建时间");
								  
			 /*以下就是对处理Excel里的数据， 横着取数据，主要是这一步，其他基本都不要改*/
			foreach($data as $k => $v){
				 $k +=2;
				 $objActSheet ->setCellValue('A'.$k, $v['sku']); 
				 $objActSheet ->setCellValue('B'.$k, $v['default_styles']);  //默认款
				 $objActSheet ->setCellValue('C'.$k, $v['price_type']); //价格类型
				 //$objActSheet ->setCellValue('C'.$k, $v['independent_product']);
				 $objActSheet ->setCellValue('D'.$k, $v['brand']);    //品牌
				 $objActSheet ->setCellValue('E'.$k, $v['logo']);	
				 $objActSheet ->setCellValue('F'.$k, $v['product_material']);  //产品材质
				 $objActSheet ->setCellValue('G'.$k, $v['product_type']);    //产品类型
				 $objActSheet ->setCellValue('H'.$k, $v['independent_product']);  //自主产品
				 $objActSheet ->setCellValue('I'.$k, $v['fictitious_product']);  //虚拟产品
				 $objActSheet ->setCellValue('J'.$k, $v['weight']);  //重量
				 $objActSheet ->setCellValue('K'.$k, $v['cost_price']); //成本价
				 $objActSheet ->setCellValue('L'.$k, $v['ali_lt']);  //批发散货价  
				 $objActSheet ->setCellValue('M'.$k, $v['ali_gt']);   //批发订货价
				 $objActSheet ->setCellValue('N'.$k, $v['aliexpress']); //零售价
				 //$objActSheet ->setCellValue('M'.$k, $v['ioffer']);    
				 $objActSheet ->setCellValue('O'.$k, $v['custom_one']);  //自定义1
				 $objActSheet ->setCellValue('P'.$k, $v['custom_two']);    //自定义2
				 $objActSheet ->setCellValue('Q'.$k, $v['custom_three']);	//自定义3
				 $objActSheet ->setCellValue('R'.$k, $v['custom_four']);	//自定义4
				 $objActSheet ->setCellValue('S'.$k, $v['supplier']);    //供应商 
				 $objActSheet ->setCellValue('T'.$k, $v['buyer']);  //采购员
				 $objActSheet ->setCellValue('U'.$k, $v['addtime']); //产品创建时间
            }
		}else{
			$objActSheet ->setCellValue('A1', 'SKU');       
			$objActSheet ->setCellValue('B1', '默认款式');
			//$objActSheet ->setCellValue('C1', '线上产品');
			$objActSheet ->setCellValue('C1', "价格类型");
			$objActSheet ->setCellValue('D1', "品牌");    
			$objActSheet ->setCellValue('E1', "LOGO");
			$objActSheet ->setCellValue('F1', "产品材质");
			$objActSheet ->setCellValue('G1', "产品类型"); 
			$objActSheet ->setCellValue('H1', "自主订货产品");
			$objActSheet ->setCellValue('I1', "虚拟产品");   
			$objActSheet ->setCellValue('J1', "重量单位：g");
			$objActSheet ->setCellValue('K1', '成本价单位：￥');
			$objActSheet ->setCellValue('L1', "批发散货价单位：$");    
			$objActSheet ->setCellValue('M1', "批发订货价单位：$");
			$objActSheet ->setCellValue('N1', "零售价单位：$");
			//$objActSheet ->setCellValue('M1', "IOFFER指导价单位：$");    
			$objActSheet ->setCellValue('O1', $custom['one']);
			$objActSheet ->setCellValue('P1', $custom['two']);
			$objActSheet ->setCellValue('Q1', $custom['three']);    
			$objActSheet ->setCellValue('R1', $custom['four']);
			//$objActSheet ->setCellValue('S1', "供应商");  //如果 $acc_type['supplier'] =='1' 才显示， 否则不显示
			$objActSheet ->setCellValue('S1', "采购员");
			$objActSheet ->setCellValue('T1', "产品创建时间");
								  
			 /*以下就是对处理Excel里的数据， 横着取数据，主要是这一步，其他基本都不要改*/
			foreach($data as $k => $v){
				 $k +=2;
				 $objPHPExcel->setActiveSheetIndex(0);
							 //Excel的第A列，uid是你查出数组的键值，下面以此类推
				$objActSheet ->setCellValue('A'.$k, $v['sku']); 
				 $objActSheet ->setCellValue('B'.$k, $v['default_styles']);  //默认款
				 $objActSheet ->setCellValue('C'.$k, $v['price_type']); //价格类型
				 //$objActSheet ->setCellValue('C'.$k, $v['independent_product']);
				 $objActSheet ->setCellValue('D'.$k, $v['brand']);    //品牌
				 $objActSheet ->setCellValue('E'.$k, $v['logo']);	
				 $objActSheet ->setCellValue('F'.$k, $v['product_material']);  //产品材质
				 $objActSheet ->setCellValue('G'.$k, $v['product_type']);    //产品类型
				 $objActSheet ->setCellValue('H'.$k, $v['independent_product']);  //自主产品
				 $objActSheet ->setCellValue('I'.$k, $v['fictitious_product']);  //虚拟产品
				 $objActSheet ->setCellValue('J'.$k, $v['weight']);  //重量
				 $objActSheet ->setCellValue('K'.$k, $v['cost_price']); //成本价
				 $objActSheet ->setCellValue('L'.$k, $v['ali_lt']);  //批发散货价  
				 $objActSheet ->setCellValue('M'.$k, $v['ali_gt']);   //批发订货价
				 $objActSheet ->setCellValue('N'.$k, $v['aliexpress']); //零售价
				 //$objActSheet ->setCellValue('M'.$k, $v['ioffer']);    
				 $objActSheet ->setCellValue('O'.$k, $v['custom_one']);  //自定义1
				 $objActSheet ->setCellValue('P'.$k, $v['custom_two']);    //自定义2
				 $objActSheet ->setCellValue('Q'.$k, $v['custom_three']);	//自定义3
				 $objActSheet ->setCellValue('R'.$k, $v['custom_four']);	//自定义4
				 //$objActSheet ->setCellValue('S'.$k, $v['supplier']);    //供应商 
				 $objActSheet ->setCellValue('S'.$k, $v['buyer']);  //采购员
				 $objActSheet ->setCellValue('T'.$k, $v['addtime']); //产品创建时间
			}
		}
		$fileName = '产品目录表';
		$date = date("Y-m-d",time());
		$fileName .= "_{$date}.xls";
	
		//重命名表
		// $objPHPExcel->getActiveSheet()->setTitle('test');
		//设置活动单指数到第一个表,所以Excel打开这是第一个表
		$objPHPExcel->setActiveSheetIndex(0);
		header('Content-Type: application/vnd.ms-excel');
		header("Content-Disposition: attachment;filename=\"$fileName\"");	//图片另存为
		header('Cache-Control: max-age=0');

		$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
		$objWriter->save('php://output'); //文件通过浏览器下载
		exit;
	}
	
	
	//导出满足条件部份属性的产品  
	/*public function search_daochu(){
		
		$sku 					= I('get.sku','','htmlspecialchars');
		$default_styles 		= I('get.default_styles','','htmlspecialchars');
		$independent_product 	= I('get.independent_product','','htmlspecialchars');
		$brand 					= I('get.brand','','htmlspecialchars');
		$logo 					= I('get.logo','','htmlspecialchars');
		$product_material 		= I('get.product_material','','htmlspecialchars');
		$product_type 			= I('get.product_type','','htmlspecialchars');
		$weight_before 			= I('get.weight_before','','htmlspecialchars');
		$weight_after			= I('get.weight_after','','htmlspecialchars');
		$cost_price_before 		= I('get.cost_price_before','','htmlspecialchars');
		$cost_price_after		= I('get.cost_price_after','','htmlspecialchars');
		$ali_lt_start 			= I('get.ali_lt_start','','htmlspecialchars');
		$ali_lt_end 			= I('get.ali_lt_end','','htmlspecialchars');
		$ali_gt_start			= I('get.ali_gt_start','','htmlspecialchars');
		$ali_gt_end 			= I('get.ali_gt_end','','htmlspecialchars');
		$aliexpress_start 		= I('get.aliexpress_start','','htmlspecialchars');
		$aliexpress_end 		= I('get.aliexpress_end','','htmlspecialchars');
		$ioffer_start 			= I('get.ioffer_start','','htmlspecialchars');
		$ioffer_end 			= I('get.ioffer_end','','htmlspecialchars');
		$custom_one 			= I('get.custom_one','','htmlspecialchars');
		$custom_two 			= I('get.custom_two','','htmlspecialchars');
		$custom_three			= I('get.custom_three','','htmlspecialchars');
		$custom_four 			= I('get.custom_four','','htmlspecialchars');
		$supplier 				= I('get.supplier','','htmlspecialchars');
		$buyer 					= I('get.buyer','','htmlspecialchars');
		$starttime 				= I('get.starttime','','htmlspecialchars');
		$endtime 				= I('get.endtime','','htmlspecialchars');
		
		$res = D('product')->searchListAll($sku,$default_styles,$independent_product,$brand,$logo,$product_material,$product_type,$weight_before,$weight_after,$cost_price_before,$cost_price_after,$ali_lt_start,$ali_lt_end,$ali_gt_start,$ali_gt_end,$aliexpress_start,$aliexpress_end,$ioffer_start,$ioffer_end,$custom_one,$custom_two,$custom_three,$custom_four,$supplier,$buyer,$starttime,$endtime);
		
		$id_list = $res['product_list'];
		$name = $_SESSION['user'];
		$acc_type = M('account')->field('cost_price,supplier')->where(array('username'=>$name))->find();
		
		
		
		foreach($id_list as $key=>$val){
			if($acc_type['supplier'] =='1'){
			$data[$key] = M('product')->field('sku,default_styles,independent_product,brand,logo,product_material,product_type,weight,cost_price,supplier,addtime')->where(array('id'=>$val['id']))->find();
			}else{
				$data[$key] = M('product')->field('sku,default_styles,independent_product,brand,logo,product_material,product_type,weight,cost_price,addtime')->where(array('id'=>$val['id']))->find();
			}
			
			
		}
		foreach($data as $key=>$val){
			if($val['default_styles']=='1'){
				$data[$key]['default_styles']='是';
			}else{
				$data[$key]['default_styles']='否';
			}
			
			if($val['independent_product']=='1'){
				$data[$key]['independent_product']='是';
			}else{
				$data[$key]['independent_product']='否';
			}
			
			if($val['logo']=='1'){
				$data[$key]['logo']='是';
			}else{
				$data[$key]['logo']='否';
			}
			
			if($val['independent_product']==''){
				$data[$key]['independent_product']='';
			}
		}
		error_reporting(E_ALL);
        date_default_timezone_set('PRC');
		  
		import("Org.Util.PHPExcel");
        import("Org.Util.PHPExcel.Worksheet.Drawing");
        import("Org.Util.PHPExcel.Writer.Excel2007");
		import("Org.Util.PHPExcel.Style.NumberFormat");
		import("Org.Util.PHPExcel.Style.Alignment");
		import("Org.Util.PHPExcel.Style.Color");
		
		import("Org.Util.PHPExcel.Style.Border");
		//设定缓存模式为经gzip压缩后存入cache（还有多种方式请百度）  
		$cacheMethod = \PHPExcel_CachedObjectStorageFactory::cache_in_memory_gzip; 
		$cacheSettings = array();  
		\PHPExcel_Settings::setCacheStorageMethod($cacheMethod,$cacheSettings);  

        $objPHPExcel = new \PHPExcel();
        $objWriter = new \PHPExcel_Writer_Excel2007($objPHPExcel);
    
        $objActSheet = $objPHPExcel->getActiveSheet();
		
		if($acc_type['supplier'] =='1'){
			$objActSheet->setCellValue('A1', 'SKU');    
			$objActSheet ->setCellValue('B1', '默认款式');
			$objActSheet ->setCellValue('C1', '线上产品');
			$objActSheet->setCellValue('D1', '品牌');    
			$objActSheet ->setCellValue('E1', 'LOGO');
			$objActSheet ->setCellValue('F1', '产品材质');
			$objActSheet->setCellValue('G1', "产品类型");    
			$objActSheet ->setCellValue('H1', "重量");
			$objActSheet ->setCellValue('I1', "成本价");
			$objActSheet->setCellValue('J1', "供应商");    
			$objActSheet ->setCellValue('K1', "添加时间");
								  
			 //以下就是对处理Excel里的数据， 横着取数据，主要是这一步，其他基本都不要改
			foreach($data as $k => $v){
				 $k +=2;
				 $objPHPExcel->setActiveSheetIndex(0);
							 //Excel的第A列，uid是你查出数组的键值，下面以此类推
				 $objActSheet->setCellValue('A'.$k, $v['sku']);    
				 $objActSheet ->setCellValue('B'.$k, $v['default_styles']);
				 $objActSheet ->setCellValue('C'.$k, $v['independent_product']);
				 
				 $objActSheet->setCellValue('D'.$k, $v['brand']);    
				 $objActSheet ->setCellValue('E'.$k, $v['logo']);
				 $objActSheet ->setCellValue('F'.$k, $v['product_material']);
				 
				 
				 $objActSheet->setCellValue('G'.$k, $v['product_type']);    
				 $objActSheet ->setCellValue('H'.$k, $v['weight']);
				 $objActSheet ->setCellValue('I'.$k, $v['cost_price']);
				 
				 $objActSheet->setCellValue('J'.$k, $v['supplier']);    
				 $objActSheet ->setCellValue('K'.$k, $v['addtime']);
            }
		}else{
			$objActSheet->setCellValue('A1', 'SKU');    
			$objActSheet ->setCellValue('B1', '默认款式');
			$objActSheet ->setCellValue('C1', '线上产品');
			$objActSheet->setCellValue('D1', '品牌');    
			$objActSheet ->setCellValue('E1', 'LOGO');
			$objActSheet ->setCellValue('F1', '产品材质');
			$objActSheet->setCellValue('G1', "产品类型");    
			$objActSheet ->setCellValue('H1', "重量");
			$objActSheet ->setCellValue('I1', "成本价");
			
			$objActSheet ->setCellValue('K1', "添加时间");
								  
			 //以下就是对处理Excel里的数据， 横着取数据，主要是这一步，其他基本都不要改
			foreach($data as $k => $v){
				 $k +=2;
				 $objPHPExcel->setActiveSheetIndex(0);
							 //Excel的第A列，uid是你查出数组的键值，下面以此类推
				 $objActSheet->setCellValue('A'.$k, $v['sku']);    
				 $objActSheet ->setCellValue('B'.$k, $v['default_styles']);
				 $objActSheet ->setCellValue('C'.$k, $v['independent_product']);
				 
				 $objActSheet->setCellValue('D'.$k, $v['brand']);    
				 $objActSheet ->setCellValue('E'.$k, $v['logo']);
				 $objActSheet ->setCellValue('F'.$k, $v['product_material']);
				 
				 
				 $objActSheet->setCellValue('G'.$k, $v['product_type']);    
				 $objActSheet ->setCellValue('H'.$k, $v['weight']);
				 $objActSheet ->setCellValue('I'.$k, $v['cost_price']);
				 
				 $objActSheet ->setCellValue('J'.$k, $v['addtime']);
			}
		}
		$fileName = '产品目录表';
		$date = date("Y-m-d",time());
		$fileName .= "_{$date}.xls";
	
		//重命名表
		// $objPHPExcel->getActiveSheet()->setTitle('test');
		//设置活动单指数到第一个表,所以Excel打开这是第一个表
		$objPHPExcel->setActiveSheetIndex(0);
		header('Content-Type: application/vnd.ms-excel');
		header("Content-Disposition: attachment;filename=\"$fileName\"");	//图片另存为
		header('Cache-Control: max-age=0');

		$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
		$objWriter->save('php://output'); //文件通过浏览器下载
		exit;
	}*/
	
	/**
		* 导出数据为excel表格
		*@param $data    一个二维数组,结构如同从数据库查出来的数组
		*@param $title   excel的第一行标题,一个数组,如果为空则没有标题
		*@param $filename 下载的文件名
		*@examlpe 
		$stu = M ('User');
		$arr = $stu -> select();
		exportexcel($arr,array('id','账户','密码','昵称'),'文件名!');
	*/
	public function exportexcel($data=array(),$title=array(),$filename='report'){
		/*header("Content-Type: application/vnd.ms-execl"); 
		header("Content-Type: application/vnd.ms-excel; charset=gb2312");
		header("Content-Disposition: attachment; filename=$filename"); 
		header("Pragma: no-cache"); 
		header("Expires: 0");*/
		
		
		header("Content-type:application/octet-stream");
		header("Accept-Ranges:bytes");
		header("Content-type:applicationnd.ms-excel");  
		header("Content-Type: application/vnd.ms-excel; charset=gb2312");
		header("Content-Disposition:attachment;filename=".$filename.".xls");
		header("Pragma: no-cache");
		header("Expires: 0");
		
		
		
		
		//导出xls 开始
		if (!empty($title)){
			foreach ($title as $k => $v) {
				$title[$k]=iconv("UTF-8", "GB2312",$v);
				//$title[$k]=$v;
			}
			$title= implode("\t", $title);
			echo "$title\n";
		}
		
		if (!empty($data)){
			foreach($data as $key=>$val){
				foreach ($val as $ck => $cv) {
					$data[$key][$ck]=iconv("UTF-8", "GB2312", $cv);
				}
				$data[$key]=implode("\t", $data[$key]);
				
			}
			echo implode("\n",$data);
		}
	}

	//生成推荐表
	public function promoted_products(){
		$name = $_SESSION['user'];
		$acc_type = M('account')->field('cost_price,supplier')->where(array('username'=>$name))->find();
		$sku 					= I('get.sku','','htmlspecialchars');
		$default_styles 		= I('get.default_styles','','htmlspecialchars');
		$independent_product 	= I('get.independent_product','','htmlspecialchars');
		$brand 					= I('get.brand','','htmlspecialchars');
		$logo 					= I('get.logo','','htmlspecialchars');
		$product_material 		= I('get.product_material','','htmlspecialchars');
		$product_type 			= I('get.product_type','','htmlspecialchars');
		$weight_before 			= I('get.weight_before','','htmlspecialchars');
		$weight_after			= I('get.weight_after','','htmlspecialchars');
		$cost_price_before 		= I('get.cost_price_before','','htmlspecialchars');
		$cost_price_after		= I('get.cost_price_after','','htmlspecialchars');
		$ali_lt_start 			= I('get.ali_lt_start','','htmlspecialchars');
		$ali_lt_end 			= I('get.ali_lt_end','','htmlspecialchars');
		$ali_gt_start			= I('get.ali_gt_start','','htmlspecialchars');
		$ali_gt_end 			= I('get.ali_gt_end','','htmlspecialchars');
		$aliexpress_start 		= I('get.aliexpress_start','','htmlspecialchars');
		$aliexpress_end 		= I('get.aliexpress_end','','htmlspecialchars');
		$ioffer_start 			= I('get.ioffer_start','','htmlspecialchars');
		$ioffer_end 			= I('get.ioffer_end','','htmlspecialchars');
		$custom_one 			= I('get.custom_one','','htmlspecialchars');
		$custom_two 			= I('get.custom_two','','htmlspecialchars');
		$custom_three			= I('get.custom_three','','htmlspecialchars');
		$custom_four 			= I('get.custom_four','','htmlspecialchars');
		$supplier 				= I('get.supplier','','htmlspecialchars');
		$buyer 					= I('get.buyer','','htmlspecialchars');
		$starttime 				= I('get.starttime','','htmlspecialchars');
		$endtime 				= I('get.endtime','','htmlspecialchars');
		if($acc_type['supplier']==1){
			$res = D('product')->searchListAll($sku,$default_styles,$independent_product,$brand,$logo,$product_material,$product_type,$weight_before,$weight_after,$cost_price_before,$cost_price_after,$ali_lt_start,$ali_lt_end,$ali_gt_start,$ali_gt_end,$aliexpress_start,$aliexpress_end,$ioffer_start,$ioffer_end,$custom_one,$custom_two,$custom_three,$custom_four,$supplier,$buyer,$starttime,$endtime);
		}else{
			$supplier = '';
			$res = D('product')->searchListAll($sku,$default_styles,$independent_product,$brand,$logo,$product_material,$product_type,$weight_before,$weight_after,$cost_price_before,$cost_price_after,$ali_lt_start,$ali_lt_end,$ali_gt_start,$ali_gt_end,$aliexpress_start,$aliexpress_end,$ioffer_start,$ioffer_end,$custom_one,$custom_two,$custom_three,$custom_four,$supplier,$buyer,$starttime,$endtime);
		}
		$data = $res['product_list'];
        // 导出Exl
        import("Org.Util.PHPExcel");
        import("Org.Util.PHPExcel.Worksheet.Drawing");
        import("Org.Util.PHPExcel.Writer.Excel2007");
		import("Org.Util.PHPExcel.Style.NumberFormat");
		import("Org.Util.PHPExcel.Style.Alignment");
		import("Org.Util.PHPExcel.Style.Color");
		
		import("Org.Util.PHPExcel.Style.Border");
		
		\PHPExcel_CachedObjectStorageFactory::cache_in_memory_serialized; 	
			
		
		
        $objPHPExcel = new \PHPExcel();
        $objWriter = new \PHPExcel_Writer_Excel2007($objPHPExcel);
    
        $objActSheet = $objPHPExcel->getActiveSheet();
        
        // 水平居中（位置很重要，建议在最初始位置）
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        
        
        // 垂直居中
        $objPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('E')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('F')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('G')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
        
		//合并列单元
		//设置宽度
		// 设置个表格宽度
        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
        $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
        $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(1);
        $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
        $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(1);
        $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(25);
		
        $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(1);
        $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(25);
		
		
            $objDrawing[1] = new \PHPExcel_Worksheet_Drawing();
            $objDrawing[1]->setPath('Public/img/logo.png');
            // 设置宽度高度
            $objDrawing[1]->setHeight(100);//照片高度
            $objDrawing[1]->setWidth('120'); //照片宽度
            /*设置图片要插入的单元格*/
			
            $objDrawing[1]->setCoordinates('A1');
			
            // 图片偏移距离
            $objDrawing[1]->setOffsetX(30);
            $objDrawing[1]->setOffsetY(0);
            $objDrawing[1]->setWorksheet($objPHPExcel->getActiveSheet());
			
			$objPHPExcel->getActiveSheet()->mergeCells('A1:H1');
			
			$objPHPExcel->getActiveSheet()->getStyle('A1')->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					'size'=>'26'

                ),

            )

        );
       		$objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_BOTTOM);
			$objActSheet->setCellValue('A1', 'Touch Love Jewelry Co., Ltd.');
			
            $objActSheet->getRowDimension(1)->setRowHeight(45);
			
			$objPHPExcel->getActiveSheet()->mergeCells('A2:H2');
			$objActSheet->setCellValue('A2', 'Add: R801 Tairong business building, No.63 Xizeng Road, GuangZhou, China');
            
			
			$objPHPExcel->getActiveSheet()->mergeCells('A3:H3');
			$objActSheet->setCellValue('A3', 'Email:sale@touch-love-jewelry.com  TEL:+86-20-81537159');
			
			$objPHPExcel->getActiveSheet()->getStyle('A4')->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					'size'=>'14'

                ),

            )

        );

			$objPHPExcel->getActiveSheet()->mergeCells('A4:H4');
			$objActSheet->setCellValue('A4', 'Website: http://touchlove.en.alibaba.com');
			
			
			$objPHPExcel->getActiveSheet()->mergeCells('A5:H5');
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('A5')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
       	 	$objPHPExcel->getActiveSheet()->getStyle('A5')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_BOTTOM);
			$objActSheet->setCellValue('A5', "Welcome to view our product. If you like any product, please send me the Code No. and Quantity Enjoy your shopping");
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('A5')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objActSheet->getRowDimension(5)->setRowHeight(20);
			
		
			
		$objPHPExcel->getActiveSheet()->getStyle('A6')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
		
		$objActSheet->setCellValue('A6', '1');
		$objPHPExcel->getActiveSheet()->mergeCells('B6:H6');
		$objActSheet->setCellValue('B6', 'Based on FOB China price');
		$objPHPExcel->setActiveSheetIndex(0)->getStyle('A6')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
		$objPHPExcel->setActiveSheetIndex(0)->getStyle('B6')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);	
		
		$objActSheet->setCellValue('A7', '2');
		$objPHPExcel->getActiveSheet()->mergeCells('B7:H7');
		$objActSheet->setCellValue('B7', 'Mini Order 3 pcs / model');
		$objPHPExcel->setActiveSheetIndex(0)->getStyle('A7')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
		$objPHPExcel->setActiveSheetIndex(0)->getStyle('B7')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);	
			
		$count = ((count($data)%4));	//一共需要几行
		$countAll = count($data);				//一共有几条数据
		$sum_count = (ceil(sizeof($data)/4))*3+8;
		//var_dump($data);die;
		foreach($data as $key=>$value){ 
			$i=8;
			$i+=$key;
			
			//echo $i;
			if(is_int($i/4)){
				$_SESSION['y']='B';
				$_SESSION['Photo']=$key/4*3+8;
				$_SESSION['sku']=$key/4*3+9;
				$_SESSION['price']=$key/4*3+10;
				$objActSheet->setCellValue('A'.$_SESSION['Photo'], 'Photo');   
				
				$objActSheet->getRowDimension($_SESSION['Photo'])->setRowHeight(104); 
				$objActSheet->setCellValue('A'.$_SESSION['sku'], 'Code No.');  
				
				$objActSheet->getRowDimension($_SESSION['sku'])->setRowHeight(20); 
				$objActSheet->setCellValue('A'.$_SESSION['price'], 'Unit price'); 
				
				$objActSheet->getRowDimension($_SESSION['price'])->setRowHeight(40); 
				
				
			}elseif(is_int(($i+3)/4)){
				$_SESSION['y']='D';
			}elseif(is_int(($i+2)/4)){
				$_SESSION['y']='F';
			}else{
				$_SESSION['y']='H';
			}
			if(is_int($key/4)){
				$_SESSION['i']=$i;
			}
		
			
			
			$dir = "public/images/".$value['sku']; // 文件夹的名称
			$file = array();
			if (is_dir($dir)){
			  if ($dh = opendir($dir)){
				while (($file[] = readdir($dh)) !== false){
				}
				closedir($dh);
			  }
			}
			
			
			
			if( in_array("A.jpg",$file) /*|| in_array("A.jpeg",$file) || in_array("A.png",$file) || in_array("A.gif",$file) || in_array("A.JPG",$file) || in_array("A.JPEG",$file) || in_array("A.PNG",$file) || in_array("A.GIF",$file)*/){
					  	$objDrawing[$i] = new \PHPExcel_Worksheet_Drawing();
						$path = $value['sku'].'/A.jpg';
						
					
						
						$objDrawing[$i]->setPath('Public/images/'.$path);
						// 设置宽度高度
						$objDrawing[$i]->setHeight(60);//照片高度
						$objDrawing[$i]->setWidth(160); //照片宽度
						/*设置图片要插入的单元格*/
						$objDrawing[$i]->setCoordinates($_SESSION['y'].$_SESSION['Photo']);
						// 图片偏移距离
						$objDrawing[$i]->setOffsetX(5);
						$objDrawing[$i]->setOffsetY(5);
						$objDrawing[$i]->setWorksheet($objPHPExcel->getActiveSheet());
						
						$objActSheet->getRowDimension($_SESSION['Photo'])->setRowHeight(130); 
						
					}else{
						$objActSheet->setCellValue($_SESSION['y'].$_SESSION['Photo'], '图片丢失'); 
						
        				$objPHPExcel->setActiveSheetIndex(0)->getStyle($_SESSION['y'].$_SESSION['Photo'])->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
						
        				$objPHPExcel->getActiveSheet()->getStyle($_SESSION['y'].$_SESSION['Photo'])->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
						
				}
			
				
			$objActSheet->setCellValue($_SESSION['y'].$_SESSION['sku'], $value['sku']);   
			
 $objPHPExcel->setActiveSheetIndex(0)->getStyle($_SESSION['y'].$_SESSION['sku'])->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);       
 $objPHPExcel->getActiveSheet()->getStyle($_SESSION['y'].$_SESSION['sku'])->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
 
			$objActSheet->getRowDimension($_SESSION['sku'])->setRowHeight(20);  
			$objActSheet->setCellValue($_SESSION['y'].$_SESSION['price'], 'US$'.$value['ali_lt']);
			
			
			 $objPHPExcel->setActiveSheetIndex(0)->getStyle($_SESSION['y'].$_SESSION['price'])->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);       
			 $objPHPExcel->getActiveSheet()->getStyle($_SESSION['y'].$_SESSION['price'])->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
			
			$objActSheet->getRowDimension($_SESSION['price'])->setRowHeight(40); 
		}


		/*
		
		****************************  账户信息 输出开始 ************   */

		$k=$_SESSION['price'];
		$objPHPExcel->getActiveSheet()->mergeCells('A'.($k+14).':G'.($k+14));
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('A'.($k+14))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objActSheet->setCellValue('A'.($k+14), 'Account details for orders:');  
			
			$objPHPExcel->getActiveSheet()->getStyle('A'.($k+14))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			
			$objPHPExcel->getActiveSheet()->mergeCells('A'.($k+15).':G'.($k+15));
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('A'.($k+15))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objActSheet->setCellValue('A'.($k+15), 'T/T: ($30 handle fee is needed for each payment)');  
			
			
			
			
			
			
			$objPHPExcel->getActiveSheet()->mergeCells('A'.($k+16).':A'.($k+21));
			$objPHPExcel->getActiveSheet()->getStyle('A'.($k+16))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objActSheet->setCellValue('A'.($k+16), 'Bank Details');
			
			
			$objActSheet->setCellValue('B'.($k+16), 'Company Name:');
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('B'.($k+16))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->getStyle('B'.($k+16))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'11'

                ),

            )

        );
			$objPHPExcel->getActiveSheet()->mergeCells('C'.($k+16).':G'.($k+16));
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('C'.($k+16))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->getStyle('C'.($k+16))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objActSheet->setCellValue('C'.($k+16), 'TOUCH LOVE JEWELRY CO., LIMITED');
			
			
			
			$objActSheet->setCellValue('B'.($k+17), 'Beneficiary Bank:');
			$objPHPExcel->getActiveSheet()->getStyle('B'.($k+17))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('B'.($k+17))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('C'.($k+17))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->getStyle('C'.($k+17))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objPHPExcel->getActiveSheet()->mergeCells('C'.($k+17).':G'.($k+17));
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('C'.($k+18))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objActSheet->setCellValue('C'.($k+17), 'HSBC Hong Kong');
			
			$objPHPExcel->getActiveSheet()->getStyle('B'.($k+18))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objActSheet->setCellValue('B'.($k+18), 'Branch code');
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('B'.($k+18))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->getStyle('C'.($k+18))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('C'.($k+19))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->mergeCells('C'.($k+18).':G'.($k+18));
			$objActSheet->setCellValue('C'.($k+18), " 004");
			
			
			$objPHPExcel->getActiveSheet()->getStyle('B'.($k+19))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objActSheet->setCellValue('B'.($k+19), 'Bank Account No:');
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('B'.($k+19))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('C'.($k+19))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->getStyle('C'.($k+19))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objPHPExcel->getActiveSheet()->mergeCells('C'.($k+19).':G'.($k+19));
			$objActSheet->setCellValue('C'.($k+19), '817-810799-838');
			
			
			
			$objPHPExcel->getActiveSheet()->getStyle('B'.($k+20))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			
			$objActSheet->setCellValue('B'.($k+20), 'Bank Address:');
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('B'.($k+20))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->getStyle('C'.($k+20))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
		 	
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('C'.($k+20))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->mergeCells('C'.($k+20).':G'.($k+20));
			$objActSheet->setCellValue('C'.($k+20), "1 Queen's Road Central, HongKong");
			
			
			$objPHPExcel->getActiveSheet()->getStyle('B'.($k+21))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objActSheet->setCellValue('B'.($k+21), 'Swift BIC:');
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('B'.($k+21))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->getStyle('C'.($k+21))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('C'.($k+21))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->mergeCells('C'.($k+21).':G'.($k+21));
			$objPHPExcel->getActiveSheet()->getStyle('C'.($k+21))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objActSheet->setCellValue('C'.($k+21), 'HSBCHKHHHKH');
			
			
			$objPHPExcel->getActiveSheet()->mergeCells('A'.($k+22).':G'.($k+22));
			$objActSheet->setCellValue('A'.($k+22), '');
			
			
			
			
			$objActSheet->setCellValue('A'.($k+23), 'Western Union');
			$objPHPExcel->getActiveSheet()->mergeCells('B'.($k+23).':G'.($k+23));
			$objActSheet->setCellValue('B'.($k+23), 'XIAOYAN   CHEN  ( First Name:XIAOYAN, Last Name: CHEN, Received City : GuangZhou, China)');
			
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('B'.($k+23))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			
			$objPHPExcel->getActiveSheet()->getStyle('A'.($k+23))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'11'

                ),

            )

        );
		
		$objPHPExcel->getActiveSheet()->getStyle('B'.($k+23))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'14'

                ),

            )

        );
		 
		



		/*   账户信息输出结束  ***************** */
        $fileName = '新品推荐表';
        $date = date("Y-m-d",time());
        $fileName .= "_{$date}.xls";

        $fileName = iconv("utf-8", "gb2312", $fileName);
        //重命名表
        // $objPHPExcel->getActiveSheet()->setTitle('test');
        //设置活动单指数到第一个表,所以Excel打开这是第一个表
        $objPHPExcel->setActiveSheetIndex(0);
        header('Content-Type: application/vnd.ms-excel');
        header("Content-Disposition: attachment;filename=\"$fileName\"");	//图片另存为
        header('Cache-Control: max-age=0');

        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('php://output'); //文件通过浏览器下载
        // END    
		
	}
	
	
	
	
	//生成推荐表  勾选
	public function get_promoted_products(){
		$ids = trim(I('get.tids','','htmlspecialchars'),'');
		$id_list = explode(',',trim($ids,','));
		
		foreach($id_list as $k=>$v){
			$data[$k] = M('product')->where(array('id'=>$v))->find();
		}
        //var_dump($data);die;
        // 导出Exl
        import("Org.Util.PHPExcel");
        import("Org.Util.PHPExcel.Worksheet.Drawing");
        import("Org.Util.PHPExcel.Writer.Excel2007");
		import("Org.Util.PHPExcel.Style.NumberFormat");
		import("Org.Util.PHPExcel.Style.Alignment");
		import("Org.Util.PHPExcel.Style.Color");
		
		import("Org.Util.PHPExcel.Style.Border");
        $objPHPExcel = new \PHPExcel();
        $objWriter = new \PHPExcel_Writer_Excel2007($objPHPExcel);
    
        $objActSheet = $objPHPExcel->getActiveSheet();
        
        // 水平居中（位置很重要，建议在最初始位置）
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        
        
        // 垂直居中
        $objPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('E')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('F')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('G')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
        
		//合并列单元
		//设置宽度
		// 设置个表格宽度
        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
        $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
        $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(1);
        $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
        $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(1);
        $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(25);
		
        $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(1);
        $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(25);
		
		
            $objDrawing[1] = new \PHPExcel_Worksheet_Drawing();
            $objDrawing[1]->setPath('Public/img/logo.png');
            // 设置宽度高度
            $objDrawing[1]->setHeight(100);//照片高度
            $objDrawing[1]->setWidth('120'); //照片宽度
            /*设置图片要插入的单元格*/
            $objDrawing[1]->setCoordinates('A1');
			
            // 图片偏移距离
            $objDrawing[1]->setOffsetX(30);
            $objDrawing[1]->setOffsetY(0);
            $objDrawing[1]->setWorksheet($objPHPExcel->getActiveSheet());
			
			
			$objPHPExcel->getActiveSheet()->mergeCells('A1:H1');
			
       		$objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('A1')->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					'size'=>'26'

                ),

            )

        );
			$objActSheet->setCellValue('A1', 'Touch Love Jewelry Co., Ltd.');
			
            $objActSheet->getRowDimension(1)->setRowHeight(45);
			
			$objPHPExcel->getActiveSheet()->mergeCells('A2:H2');
			$objActSheet->setCellValue('A2', 'Add: R801 Tairong business building, No.63 Xizeng Road, GuangZhou, China');
            
			
			$objPHPExcel->getActiveSheet()->mergeCells('A3:H3');
			$objActSheet->setCellValue('A3', 'Email:sale@touch-love-jewelry.com  TEL:+86-20-81537159');
			$objPHPExcel->getActiveSheet()->getStyle('A4')->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					'size'=>'14'

                ),

            )

        );
			$objPHPExcel->getActiveSheet()->mergeCells('A4:H4');
			$objActSheet->setCellValue('A4', 'Website: http://touchlove.en.alibaba.com');
			
			$objPHPExcel->getActiveSheet()->mergeCells('A5:H5');
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('A5')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
       	 	$objPHPExcel->getActiveSheet()->getStyle('A5')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_BOTTOM);
			$objActSheet->setCellValue('A5', "Welcome to view our product. If you like any product, please send me the Code No. and Quantity  Enjoy your shopping");
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('A5')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objActSheet->getRowDimension(5)->setRowHeight(20);
			
			
			
		$objPHPExcel->getActiveSheet()->getStyle('A6')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
		
		$objActSheet->setCellValue('A6', '1');
		$objPHPExcel->getActiveSheet()->mergeCells('B6:H6');
		$objActSheet->setCellValue('B6', 'Based on FOB China price');	
		$objPHPExcel->setActiveSheetIndex(0)->getStyle('B6')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);	
		$objActSheet->setCellValue('A7', '2');
		$objPHPExcel->getActiveSheet()->mergeCells('B7:H7');
		$objActSheet->setCellValue('B7', 'Mini Order 3 pcs / model');
		
		$objPHPExcel->setActiveSheetIndex(0)->getStyle('B7')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			
		$count = ((count($data)%4));	//一共需要几行
		$countAll = count($data);				//一共有几条数据
		$sum_count = (ceil(sizeof($data)/4))*3+8;
		//var_dump($data);die;
		foreach($data as $key=>$value){ 
			$i=8;
			$i+=$key;
			
			//echo $i;
			if(is_int($i/4)){
				$_SESSION['y']='B';
				$_SESSION['Photo']=$key/4*3+8;
				$_SESSION['sku']=$key/4*3+9;
				$_SESSION['price']=$key/4*3+10;
				$objActSheet->setCellValue('A'.$_SESSION['Photo'], 'Photo');   
				
				$objActSheet->getRowDimension($_SESSION['Photo'])->setRowHeight(120); 
				$objActSheet->setCellValue('A'.$_SESSION['sku'], 'Code No.');  
				
				$objActSheet->getRowDimension($_SESSION['sku'])->setRowHeight(20); 
				$objActSheet->setCellValue('A'.$_SESSION['price'], 'Unit price'); 
				
				$objActSheet->getRowDimension($_SESSION['price'])->setRowHeight(40); 
			}elseif(is_int(($i+3)/4)){
				$_SESSION['y']='D';	
			}elseif(is_int(($i+2)/4)){
				$_SESSION['y']='F';
			}else{
				$_SESSION['y']='H';
			}
			if(is_int($key/4)){
				$_SESSION['i']=$i;
			}
		
			$dir = "public/images/".$value['sku']; // 文件夹的名称
			
			$file = array();
			if (is_dir($dir)){
			  if ($dh = opendir($dir)){
				while (($tmpfile = readdir($dh)) !== false){
					$file[] = strtolower($tmpfile);
				}
				closedir($dh);
			  }
			}
			//
			if( in_array("a.jpg",$file)/* || in_array("A.jpeg",$file) || in_array("A.png",$file) || in_array("A.gif",$file) || in_array("A.JPG",$file) || in_array("A.JPEG",$file) || in_array("A.PNG",$file) || in_array("A.GIF",$file)*/){
					  	$objDrawing[$i] = new \PHPExcel_Worksheet_Drawing();
						$path = $value['sku'].'/A.jpg';
						$objDrawing[$i]->setPath('Public/images/'.$path);
						// 设置宽度高度
						$objDrawing[$i]->setHeight(60);//照片高度
						$objDrawing[$i]->setWidth(160); //照片宽度
						/*设置图片要插入的单元格*/
						$objDrawing[$i]->setCoordinates($_SESSION['y'].$_SESSION['Photo']);
						// 图片偏移距离
						$objDrawing[$i]->setOffsetX(5);
						$objDrawing[$i]->setOffsetY(5);
						$objDrawing[$i]->setWorksheet($objPHPExcel->getActiveSheet());
						
						$objActSheet->getRowDimension($_SESSION['Photo'])->setRowHeight(130);
					}else{
						$objActSheet->setCellValue($_SESSION['y'].$_SESSION['Photo'], '图片丢失'); 
						
        				$objPHPExcel->setActiveSheetIndex(0)->getStyle($_SESSION['y'].$_SESSION['Photo'])->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
						
        				$objPHPExcel->getActiveSheet()->getStyle($_SESSION['y'].$_SESSION['Photo'])->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
				}
			
			$objActSheet->setCellValue($_SESSION['y'].$_SESSION['sku'], $value['sku']);   
			
 $objPHPExcel->setActiveSheetIndex(0)->getStyle($_SESSION['y'].$_SESSION['sku'])->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);       
 $objPHPExcel->getActiveSheet()->getStyle($_SESSION['y'].$_SESSION['sku'])->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
 
			$objActSheet->getRowDimension($_SESSION['sku'])->setRowHeight(20);  
			$objActSheet->setCellValue($_SESSION['y'].$_SESSION['price'], 'US$'.$value['ali_lt']);
			
			
 $objPHPExcel->setActiveSheetIndex(0)->getStyle($_SESSION['y'].$_SESSION['price'])->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);       
 $objPHPExcel->getActiveSheet()->getStyle($_SESSION['y'].$_SESSION['price'])->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
			
			$objActSheet->getRowDimension($_SESSION['price'])->setRowHeight(40); 
		}

		/*
		
			*************   开始输出账户信息   *****************

		 */
		

			$k=$_SESSION['price'];
		$objPHPExcel->getActiveSheet()->mergeCells('A'.($k+14).':G'.($k+14));
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('A'.($k+14))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objActSheet->setCellValue('A'.($k+14), 'Account details for orders:');  
			
			$objPHPExcel->getActiveSheet()->getStyle('A'.($k+14))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			
			$objPHPExcel->getActiveSheet()->mergeCells('A'.($k+15).':G'.($k+15));
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('A'.($k+15))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objActSheet->setCellValue('A'.($k+15), 'T/T: ($30 handle fee is needed for each payment)');  
			
			
			
			
			
			
			$objPHPExcel->getActiveSheet()->mergeCells('A'.($k+16).':A'.($k+21));
			$objPHPExcel->getActiveSheet()->getStyle('A'.($k+16))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objActSheet->setCellValue('A'.($k+16), 'Bank Details');
			
			
			$objActSheet->setCellValue('B'.($k+16), 'Company Name:');
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('B'.($k+16))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->getStyle('B'.($k+16))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'11'

                ),

            )

        );
			$objPHPExcel->getActiveSheet()->mergeCells('C'.($k+16).':G'.($k+16));
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('C'.($k+16))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->getStyle('C'.($k+16))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objActSheet->setCellValue('C'.($k+16), 'TOUCH LOVE JEWELRY CO., LIMITED');
			
			
			
			$objActSheet->setCellValue('B'.($k+17), 'Beneficiary Bank:');
			$objPHPExcel->getActiveSheet()->getStyle('B'.($k+17))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('B'.($k+17))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('C'.($k+17))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->getStyle('C'.($k+17))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objPHPExcel->getActiveSheet()->mergeCells('C'.($k+17).':G'.($k+17));
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('C'.($k+18))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objActSheet->setCellValue('C'.($k+17), 'HSBC Hong Kong');
			
			$objPHPExcel->getActiveSheet()->getStyle('B'.($k+18))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objActSheet->setCellValue('B'.($k+18), 'Branch code');
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('B'.($k+18))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->getStyle('C'.($k+18))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('C'.($k+19))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->mergeCells('C'.($k+18).':G'.($k+18));
			$objActSheet->setCellValue('C'.($k+18), " 004");
			
			
			$objPHPExcel->getActiveSheet()->getStyle('B'.($k+19))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objActSheet->setCellValue('B'.($k+19), 'Bank Account No:');
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('B'.($k+19))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('C'.($k+19))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->getStyle('C'.($k+19))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objPHPExcel->getActiveSheet()->mergeCells('C'.($k+19).':G'.($k+19));
			$objActSheet->setCellValue('C'.($k+19), '817-810799-838');
			
			
			
			$objPHPExcel->getActiveSheet()->getStyle('B'.($k+20))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			
			$objActSheet->setCellValue('B'.($k+20), 'Bank Address:');
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('B'.($k+20))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->getStyle('C'.($k+20))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
		 	
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('C'.($k+20))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->mergeCells('C'.($k+20).':G'.($k+20));
			$objActSheet->setCellValue('C'.($k+20), "1 Queen's Road Central, HongKong");
			
			
			$objPHPExcel->getActiveSheet()->getStyle('B'.($k+21))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objActSheet->setCellValue('B'.($k+21), 'Swift BIC:');
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('B'.($k+21))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->getStyle('C'.($k+21))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('C'.($k+21))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$objPHPExcel->getActiveSheet()->mergeCells('C'.($k+21).':G'.($k+21));
			$objPHPExcel->getActiveSheet()->getStyle('C'.($k+21))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'12'

                ),

            )

        );
			$objActSheet->setCellValue('C'.($k+21), 'HSBCHKHHHKH');
			
			
			$objPHPExcel->getActiveSheet()->mergeCells('A'.($k+22).':G'.($k+22));
			$objActSheet->setCellValue('A'.($k+22), '');
			
			
			
			
			$objActSheet->setCellValue('A'.($k+23), 'Western Union');
			$objPHPExcel->getActiveSheet()->mergeCells('B'.($k+23).':G'.($k+23));
			$objActSheet->setCellValue('B'.($k+23), 'XIAOYAN   CHEN  ( First Name:XIAOYAN, Last Name: CHEN, Received City : GuangZhou, China)');
			
			$objPHPExcel->setActiveSheetIndex(0)->getStyle('B'.($k+23))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			
			$objPHPExcel->getActiveSheet()->getStyle('A'.($k+23))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'11'

                ),

            )

        );
		
		$objPHPExcel->getActiveSheet()->getStyle('B'.($k+23))->applyFromArray(

            array(

                'font' => array (

                    'bold' => true,
					"color" => array("rgb" => "red"),
					'size'=>'14'

                ),

            )

        );
		


		/*             结束输出账户信息         */
        $fileName = '新品推荐表';
        $date = date("Y-m-d",time());
        $fileName .= "_{$date}.xls";

        $fileName = iconv("utf-8", "gb2312", $fileName);
        //重命名表
        // $objPHPExcel->getActiveSheet()->setTitle('test');
        //设置活动单指数到第一个表,所以Excel打开这是第一个表
        $objPHPExcel->setActiveSheetIndex(0);
        header('Content-Type: application/vnd.ms-excel');
        header("Content-Disposition: attachment;filename=\"$fileName\"");	//图片另存为
        header('Cache-Control: max-age=0');

        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('php://output'); //文件通过浏览器下载
        // END    
		
	}

		//判断是否存在该图片
			function file_exists($url)
		{
		$ch = curl_init();
		curl_setopt($ch, curlopt_url,$url);
		curl_setopt($ch, curlopt_nobody, 1); // 不下载
		curl_setopt($ch, curlopt_failonerror, 1);
		curl_setopt($ch, curlopt_returntransfer, 1);
		
		if(curl_exec($ch)!==false)
		return true;
		else
		return false;
		}
			
	
	//手动添加产品
	public function add_product(){
		$supplier = M("supplier");
		$supplier_list 	= $supplier->field("for_short")->group('for_short')->select();
		
		
		if($_POST){
			$data['sku'] 					= I('post.sku','','htmlspecialchars');
			$data['main_pic'] 				= 'A.jpg';
			$data['size_pic'] 				= 'B.jpg';
			//$data['map_depot']				= I('post.map_depot','','htmlspecialchars');
			$data['default_styles'] 		= I('post.default_styles','','htmlspecialchars');
			$data['independent_product'] 	= I('post.independent_product','','htmlspecialchars');
			$data['brand'] 					= I('post.brand','','htmlspecialchars');
			$data['logo'] 					= I('post.logo','','htmlspecialchars');
			$data['product_material'] 		= I('post.product_material','','htmlspecialchars');
			$data['product_type'] 			= I('post.product_type','','htmlspecialchars');
			$data['price_type'] 			= I('post.price_type','','htmlspecialchars');
			$data['weight'] 				= I('post.weight','','htmlspecialchars');
			$data['cost_price'] 			= I('post.cost_price','','htmlspecialchars');
			
			$control = M("price_control")->where(array('type'=>$data['product_type']))->find();
			if($control){
				$x = $data['cost_price'];
				$str1 = str_replace('x','$x',$control['ali_lt']);
				$str2 = str_replace('y1','$y1',$str1);
				$data['ali_lt']=eval("return $str2;");
				if($data['ali_lt']==NULL){
					$data['ali_lt']= 0;
				}
				
				$str3 = str_replace('x','$x',$control['ali_gt']);
				$str4 = str_replace('y2','$y2',$str3);
				$data['ali_gt']=eval("return $str4;");
				if($data['ali_gt']==NULL){
					$data['ali_gt']= 0;
				}
				$str5 = str_replace('x','$x',$control['aliexpress']);
				$str6 = str_replace('y3','$y3',$str5);
				$data['aliexpress']=eval("return $str6;");
				if($data['aliexpress']==NULL){
					$data['aliexpress']= 0;
				}
				$str7 = str_replace('x','$x',$control['ioffer']);
				$str8 = str_replace('y4','$y4',$str7);
				$data['ioffer']=eval("return $str8;");
				if($data['ioffer']==NULL){
					$data['ioffer']= 0;
				}
			}
			
			$data['custom_one'] 			= I('post.custom_one','','htmlspecialchars');
			$data['custom_two'] 			= I('post.custom_two','','htmlspecialchars');
			$data['custom_three'] 			= I('post.custom_three','','htmlspecialchars');
			$data['custom_four'] 			= I('post.custom_four','','htmlspecialchars');
			$data['supplier'] 				= I('post.supplier','','htmlspecialchars');
			$data['status'] 				= '1';
			
			
			$supplier_sql = D("supplier");
			$where['for_short'] = $data['supplier'] ;
			$buyer = $supplier_sql->buyer_list($where);
			$data['buyer'] 					= $buyer['buyer'];
			$data['addtime']				= date("Y-m-d H:i:s",time());
			$where['sku'] = $data['sku'];
			$product = M("product");
			$res = $product->where($where)->find();
			//判断是否已存在该sku
			if(empty($res)){
				$brands 		=	$data['brand'];
				$product 		=	D('product'); 
				$res_brand 		= 	$product->brand_info($brands);
				
				$product_type 		=	$data['product_type'];
				
				$type_info = M('product')->field('product_type')->where(array('product_type'=>$product_type))->find();
				if(	$type_info ==NULL){
					$add_type = M('price_control')->add(array('type'=>$data['product_type']));
				}
				$result = $product->add($data);
				
				$this->success("产品添加成功",'product_summary','3');exit;
			}else{
				$this->error("该产品已存在",'add_product','3');exit;
			}
			
		}
		
		$this->assign("supplier_list",$supplier_list);
		$this->display();
	}
	
	//修改产品信息
	public function edit_product(){
		$where['id']=$_REQUEST['id'];
		$product = M("product");
		$product_info = $product->where($where)->find();
		$custom = M("custom");
		$custom_info = $custom->find();
		$brand_info = $product->field("brand")->group('brand')->select();
		$material_info 	= $product->field("product_material")->group('product_material')->select();
		$type_info 		= $product->field("product_type")->group('product_type')->select();
		if($_POST){
			$data['sku'] 					= I('post.sku','','htmlspecialchars');
			$data['map_depot']				= I('post.map_depot','','htmlspecialchars');
			$data['default_styles'] 		= I('post.default_styles','','htmlspecialchars');
			$data['independent_product'] 	= I('post.independent_product','','htmlspecialchars');
			$data['brand'] 					= I('post.brand','','htmlspecialchars');
			$data['logo'] 					= I('post.logo','','htmlspecialchars');
			$data['product_material'] 		= I('post.product_material','','htmlspecialchars');
			$data['product_type'] 			= I('post.product_type','','htmlspecialchars');
			$data['weight'] 				= I('post.weight','','htmlspecialchars');
			$data['cost_price'] 			= I('post.cost_price','','htmlspecialchars');
			/*$data['ali_lt'] 				= I('post.ali_lt','','htmlspecialchars');
			$data['ali_gt']					= I('post.ali_gt','','htmlspecialchars');
			$data['aliexpress'] 			= I('post.aliexpress','','htmlspecialchars');
			$data['iffoer'] 				= I('post.iffoer','','htmlspecialchars');
			*/
			$data['custom_one'] 			= I('post.custom_one','','htmlspecialchars');
			$data['custom_two'] 			= I('post.custom_two','','htmlspecialchars');
			$data['custom_three'] 			= I('post.custom_three','','htmlspecialchars');
			$data['custom_four'] 			= I('post.custom_four','','htmlspecialchars');
			$data['supplier'] 				= I('post.supplier','','htmlspecialchars');
			$supplier = D("supplier");
			$for_short = $data['supplier'] ;
			$buyer = $supplier->buyer($for_short);
			$data['buyer'] 					= $buyer['buyer'];
			
			
			
			
			//根据产品类型关联价格公式
			$control = M('price_control')->field('ali_lt,ali_gt,aliexpress,ioffer')->where(array('type'=>$data['product_type']))->find();
			//根据成本价与价格公式，计算不同的指导价
			if($control['ali_lt']==NULL){
				$control['ali_lt'] = '0';
			}
			$x = $data['cost_price'];
			$str1 = str_replace('x','$x',$control['ali_lt']);
			$str2 = str_replace('y1','$y1',$str1);
			$data['ali_lt']=eval("return $str2;");	
			
			if($control['ali_gt']==NULL){
				$control['ali_gt'] = '0';
			}
			$str3 = str_replace('x','$x',$control['ali_gt']);
			$str4 = str_replace('y2','$y2',$str3);
			$data['ali_gt']=eval("return $str4;");
			
			if($control['aliexpress']==NULL){
				$control['aliexpress'] = '0';
			}
			$str5 = str_replace('x','$x',$control['aliexpress']);
			$str6 = str_replace('y3','$y3',$str5);	
			$data['aliexpress']=eval("return $str6;");
			
			if($control['ioffer']==NULL){
				$control['ioffer'] = '0';
			}
			$str7 = str_replace('x','$x',$control['ioffer']);
			$str8 = str_replace('y4','$y4',$str7);
			$data['ioffer']=eval("return $str8;");

			
			$id 		= $where['id'];
			$supplier 	= $data['supplier'] ;
			$buyer 		= $data['buyer'] ;
			$res = M("order_info")->where(array('p_id'=>$id))->save(array('supplier'=>$supplier,'buyer'=>$buyer));
			$result = $product->where($where)->save($data);
			$this->success("修改成功！");exit();
			
		}
		$supplier = M("supplier");
		$supplier_info 	= $supplier->field("for_short")->select();
		$this->assign("custom_info",$custom_info);
		$this->assign("material_info",$material_info);
		$this->assign("type_info",$type_info);
		$this->assign("product_info",$product_info);
		$this->assign("supplier_info",$supplier_info);
		$this->assign("brand_info",$brand_info);
		$this->display();
	}
	
	//批量修改产品信息
	public function edit_productAll(){
		$ids=I("get.tids",'','htmlspecialchars');
		$id_list = explode(',',trim($ids,','));
		
		if($_POST){
			$do = I('post.submit','','htmlspecialchars');
			if($do=='default_styles'){
				$data['default_styles'] 		= I('post.default_styles','','htmlspecialchars');
			}
			if($do=='independent_product'){
				$data['independent_product'] 	= I('post.independent_product','','htmlspecialchars');
			}
			if($do=='brand'){
				$data['brand'] 					= I('post.brand','','htmlspecialchars');
			}
			if($do=='logo'){
				$data['logo'] 					= I('post.logo','','htmlspecialchars');
			}
			if($do=='type'){
				$data['product_type'] 			= I('post.product_type','','htmlspecialchars');
			}
			if($do=='product_material'){
				$data['product_material'] 		= I('post.product_material','','htmlspecialchars');
			}
			if($do=='weight'){
				$data['weight'] 				= I('post.weight','','htmlspecialchars');
			}
			if($do=='cost_price'){
				$data['cost_price'] 			= I('post.cost_price','','htmlspecialchars');
			}
			if($do=='one'){
				$data['custom_one'] 			= I('post.custom_one','','htmlspecialchars');
			}
			if($do=='two'){
				$data['custom_two'] 			= I('post.custom_two','','htmlspecialchars');
			}
			if($do=='three'){
				$data['custom_three'] 			= I('post.custom_three','','htmlspecialchars');
			}
			if($do=='four'){
				$data['custom_four'] 			= I('post.custom_four','','htmlspecialchars');
			}
			if($do=='supplier'){
				$data['supplier'] 				= I('post.supplier','','htmlspecialchars');
				$supplier = D("supplier");
				$for_short = $data['supplier'] ;
				$buyer = $supplier->buyer($for_short);
				$data['buyer'] 					= $buyer['buyer'];
			}
			
			foreach($id_list as $val){
				
				if($do=='supplier'){
					$supplier 	= $data['supplier'] ;
					$buyer 		= $data['buyer'] ;
					$res = M("order_info")->where(array('p_id'=>$val))->save(array('supplier'=>$supplier,'buyer'=>$buyer));
				}
				
				if($do=='cost_price'){
					//根据产品类型关联价格公式
					$res = M("product")->field('product_type')->where(array('id'=>$val))->select();
					foreach($res as $k=>$v){
						$control = M('price_control')->field('ali_lt,ali_gt,aliexpress,ioffer')->where(array('type'=>$v['product_type']))->group('type')->find();
					
						//根据成本价与价格公式，计算不同的指导价
						if($control['ali_lt']==NULL  || $control['ali_lt']=='0'){
							$control['ali_lt'] = '0';
						}else{
							$x = $data['cost_price'];
							$str1 = str_replace('x','$x',$control['ali_lt']);
							$str2 = str_replace('y1','$y1',$str1);
							$data['ali_lt']=eval("return $str2;");	
						}
						
						
						if($control['ali_gt']==NULL){
							$control['ali_gt'] = '0';
						}else{
							$str3 = str_replace('x','$x',$control['ali_gt']);
							$str4 = str_replace('y2','$y2',$str3);
							$data['ali_gt']=eval("return $str4;");
						}
						
						
						if($control['aliexpress']==NULL){
							$control['aliexpress'] = '0';
						}else{
							$str5 = str_replace('x','$x',$control['aliexpress']);
							$str6 = str_replace('y3','$y3',$str5);	
							$data['aliexpress']=eval("return $str6;");
						}
						
						
						if($control['ioffer']==NULL){
							$control['ioffer'] = '0';
						}else{
							$str7 = str_replace('x','$x',$control['ioffer']);
							$str8 = str_replace('y4','$y4',$str7);
							$data['ioffer']=eval("return $str8;");
						}
						$result = M('product')->where(array('id'=>$val))->save($data);
					}
					
					
				}
				
				if($do!='cost_price'){
					$result = M('product')->where(array('id'=>$val))->save($data);
				}
			}
			$this->success("批量修改成功!");exit();
			
		}
		
		
		$supplier_info	= M('supplier')->field('full_name,for_short,buyer')->select();
		$custom_info 	= M('custom')->field('one,two,three,four')->find();
		$brand_info 	= M('product')->field("brand")->group('brand')->select();
		$material_info 	= M('product')->field("product_material")->group('product_material')->select();
		$type_info 		= M('product')->field("product_type")->group('product_type')->select();
		
		$this->assign('brand_info',$brand_info);
		$this->assign('material_info',$material_info);
		$this->assign('type_info',$type_info);
		$this->assign('supplier_info',$supplier_info);
		$this->assign('custom_info',$custom_info);
		$this->display();
	}
	
	//回收产品
	public function recycle_pro(){
		//判断用户是否有权限回收产品
		$p = M('account')->field('recycle_product')->where(array('username'=>$_SESSION['user']))->find();
        if(!$p['recycle_product']){
            $this->error('该用户暂无权限！');exit;
        }

		$where['id']=$_REQUEST['id'];
		$product = M("product");
		$data['status'] = "2";
		$result = $product->where($where)->save($data);
		
		if($result){
			header('Location:'.$_SERVER['HTTP_REFERER']);   
		}
	}


	
	//回收站列表
	public function recycle(){
		$name = $_SESSION['user'];
		$acc_type = M('account')->field('cost_price,supplier')->where(array('username'=>$name))->find();
		$sku = I('get.sku','','htmlspecialchars');
		$default_styles = I('get.default_styles','','htmlspecialchars');
		$independent_product = I('get.independent_product','','htmlspecialchars');
		$brand = I('get.brand','','htmlspecialchars');
		$logo = I('get.logo','','htmlspecialchars');
		
		$product_material = I('get.product_material','','htmlspecialchars');
		$product_type = I('get.product_type','','htmlspecialchars');
		$weight_before = I('get.weight_before','','htmlspecialchars');
		$weight_after = I('get.weight_after','','htmlspecialchars');
		$cost_price_before = I('get.cost_price_before','','htmlspecialchars');
		$cost_price_after = I('get.cost_price_after','','htmlspecialchars');
		$ali_lt_start = I('get.ali_lt_start','','htmlspecialchars');
		$ali_lt_end = I('get.ali_lt_end','','htmlspecialchars');
		$ali_gt_start = I('get.ali_gt_start','','htmlspecialchars');
		$ali_gt_end = I('get.ali_gt_end','','htmlspecialchars');
		$aliexpress_start = I('get.aliexpress_start','','htmlspecialchars');
		$aliexpress_end = I('get.aliexpress_end','','htmlspecialchars');
		$ioffer_start = I('get.ioffer_start','','htmlspecialchars');
		$ioffer_end = I('get.ioffer_end','','htmlspecialchars');
		$custom_one = I('get.custom_one','','htmlspecialchars');
		$custom_two = I('get.custom_two','','htmlspecialchars');
		$custom_three = I('get.custom_three','','htmlspecialchars');
		$custom_four = I('get.custom_four','','htmlspecialchars');
		$supplier = I('get.supplier','','htmlspecialchars');
		$buyer = I('get.buyer','','htmlspecialchars');
		$starttime = I('get.starttime','','htmlspecialchars');
		$endtime = I('get.endtime','','htmlspecialchars');
		
		$pageNo=empty($_REQUEST['pageNo'])?1:$_REQUEST['pageNo'];
		$pageSize=empty($_REQUEST['pageSize'])?100:$_REQUEST['pageSize'];
		
		$res = D('product')->recycleList($sku,$default_styles,$independent_product,$brand,$logo,$product_material,$product_type,$weight_before,$weight_after,$cost_price_before,$cost_price_after,$ali_lt_start,$ali_lt_end,$ali_gt_start,$ali_gt_end,$aliexpress_start,$aliexpress_end,$ioffer_start,$ioffer_end,$custom_one,$custom_two,$custom_three,$custom_four,$supplier,$buyer,$starttime,$endtime,$pageNo,$pageSize);
		$recycle_list = $res['recycle_list'];

		$custom = M("custom");
		$custom_info = $custom->find();
		$where['status'] = '1';
		$product =D('product'); 
		
		
		$brand_info 	= $product->field("brand")->group('brand')->select();
		$material_info 	= $product->field("product_material")->group('product_material')->select();
		$type_info 		= $product->field("product_type")->group('product_type')->select();
		$custom_1 	= $product->field("custom_one")->group('custom_one')->select();
		$custom_2 	= $product->field("custom_two")->group('custom_two')->select();
		$custom_3 	= $product->field("custom_three")->group('custom_three')->select();
		$custom_4 	= $product->field("custom_four")->group('custom_four')->select();
		$supplier_info 	= $product->field("supplier")->group('supplier')->select();
		$buyer_info 	= $product->field("buyer")->group('buyer')->select();
		
		$product_list = $res['product_list'];
		$count = $res['count'];
	
		$this->assign("brand_info",$brand_info);
		$this->assign("material_info",$material_info);
		$this->assign("type_info",$type_info);
		$this->assign("custom_1",$custom_1);
		$this->assign("custom_2",$custom_2);
		$this->assign("custom_3",$custom_3);
		$this->assign("custom_4",$custom_4);
		$this->assign("supplier_info",$supplier_info);
		$this->assign("buyer_info",$buyer_info);
		$this->assign("product_list",$result);
		$this->assign("count",$count);
		$this->assign("custom",$custom_info);
		$this->assign('acc_type',$acc_type);
		$this->assign("recycle_list",$recycle_list);
		
		
		
		
		
		
		$this->assign("sku",$sku);
		$this->assign("default_styles",$default_styles);
		$this->assign("independent_product",$independent_product);
		$this->assign("brand",$brand);
		$this->assign("logo",$logo);
		$this->assign("product_material",$product_material);
		$this->assign("product_type",$product_type);
		$this->assign("weight_before",$weight_before);
		$this->assign("weight_after",$weight_after);
		$this->assign("cost_price_before",$cost_price_before);
		$this->assign("cost_price_after",$cost_price_after);
		$this->assign("ali_lt_start",$ali_lt_start);
		$this->assign('ali_lt_end',$ali_lt_end);
		$this->assign("ali_gt_start",$ali_gt_start);
		$this->assign("ali_gt_end",$ali_gt_end);
		$this->assign("aliexpress_start",$aliexpress_start);
		$this->assign("aliexpress_end",$aliexpress_end);
		$this->assign("ioffer_start",$ioffer_start);
		$this->assign("ioffer_end",$ioffer_end);
		$this->assign("custom_one",$custom_one);
		$this->assign("custom_two",$custom_two);
		$this->assign("custom_three",$custom_three);
		$this->assign("custom_four",$custom_four);
		$this->assign("supplier",$supplier);
		$this->assign("buyer",$buyer);
		$this->assign("starttime",$starttime);
		$this->assign('endtime',$endtime);
		$this->display();
	}
	
	
	
	
	
	
	//复原产品
	public function recover(){
		$where['id']=$_REQUEST['id'];
		$product = M("product");
		$data['status'] = "1";
		$result = $product->where($where)->save($data);
		
		if($result){
			header('Location:'.$_SERVER['HTTP_REFERER']);   
		}
	}
	
	//批量复原产品
	public function recoverAll(){
		$ids = I('get.tids','','htmlspecialchars');
		$id_list = explode(',',trim($ids,','));
		foreach($id_list as $v){
			$where['id']=$v;
			$product = M("product");
			$data['status'] = "1";
			$result = $product->where($where)->save($data);
		}
		if($result){
			header('Location:'.$_SERVER['HTTP_REFERER']);   
		}
	}
	
	//删除产品
	public function dele(){
		$where['id']=$_REQUEST['id'];
		$product = M("product");
		$result = $product->where($where)->delete();
		
		if($result){
			header('Location:'.$_SERVER['HTTP_REFERER']);   
		}
	}
	
	//批量删除产品
	public function deleAll(){
		$ids = I('get.tids','','htmlspecialchars');
		$id_list = explode(',',trim($ids,','));
		foreach($id_list as $v){
			$where['id']=$v;
			$product = M("product");
			$data['status'] = "1";
			$result = $product->where($where)->delete();
		}
		if($result){
			header('Location:'.$_SERVER['HTTP_REFERER']);   
		}
	}
	
	
	//上传图片
	public function img_upload(){
		/****************************************************************************** 
 
		参数说明: 
		$max_file_size  : 上传文件大小限制, 单位BYTE 
		$destination_folder : 上传文件路径 
		$watermark   : 是否附加水印(1为加水印,其他为不加水印); 
		 
		使用说明: 
		1. 将PHP.INI文件里面的"extension=php_gd2.dll"一行前面的;号去掉,因为我们要用到GD库; 
		2. 将extension_dir =改为你的php_gd2.dll所在目录; 
		******************************************************************************/  
		  
		//上传文件类型列表  
		$uptypes=array(  
			'image/jpg',  
			'image/jpeg',  
			'image/png',  
			'image/pjpeg',  
			'image/gif',  
			'image/bmp',  
			'image/x-png'  
		);  
		  
		$max_file_size=2000000;     //上传文件大小限制, 单位BYTE  
		$destination_folder="__PUBLIC__picture/"; //上传文件路径  
		$watermark=1;      //是否附加水印(1为加水印,其他为不加水印);  
		$watertype=1;      //水印类型(1为文字,2为图片)  
		$waterposition=1;     //水印位置(1为左下角,2为右下角,3为左上角,4为右上角,5为居中);  
		//$waterstring="http://www.xplore.cn/";  //水印字符串  
		$waterimg="xplore.gif";    //水印图片  
		$imgpreview=1;      //是否生成预览图(1为生成,其他为不生成);  
		$imgpreviewsize=1/2;    //缩略图比例  
		
		
		
		
		if ($_SERVER['REQUEST_METHOD'] == 'POST')  
		{  
			if (!is_uploaded_file($_FILES["upfile"][tmp_name]))  
			//是否存在文件  
			{  
				 echo "图片不存在!";  
				 exit;  
			}  
		  
			$file = $_FILES["upfile"];  
			if($max_file_size < $file["size"])  
			//检查文件大小  
			{  
				echo "文件太大!";  
				exit;  
			}  
		  
			if(!in_array($file["type"], $uptypes))  
			//检查文件类型  
			{  
				echo "文件类型不符!".$file["type"];  
				exit;  
			}  
		  
			if(!file_exists($destination_folder))  
			{  
				mkdir($destination_folder);  
			}  
		  
			$filename=$file["tmp_name"];  
			$image_size = getimagesize($filename);  
			$pinfo=pathinfo($file["name"]);  
			$ftype=$pinfo['extension'];  
			$destination = $destination_folder.time().".".$ftype;  
			if (file_exists($destination) && $overwrite != true)  
			{  
				echo "同名文件已经存在了";  
				exit;  
			}  
		  
			if(!move_uploaded_file ($filename, $destination))  
			{  
				echo "移动文件出错";  
				exit;  
			}  
		  
			$pinfo=pathinfo($destination);  
			$fname=$pinfo[basename];  
			echo " <font color=red>已经成功上传</font><br>文件名:  <font color=blue>".$destination_folder.$fname."</font><br>";  
			echo " 宽度:".$image_size[0];  
			echo " 长度:".$image_size[1];  
			echo "<br> 大小:".$file["size"]." bytes";  
		  
			if($watermark==1)  
			{  
				$iinfo=getimagesize($destination,$iinfo);  
				$nimage=imagecreatetruecolor($image_size[0],$image_size[1]);  
				$white=imagecolorallocate($nimage,255,255,255);  
				$black=imagecolorallocate($nimage,0,0,0);  
				$red=imagecolorallocate($nimage,255,0,0);  
				imagefill($nimage,0,0,$white);  
				switch ($iinfo[2])  
				{  
					case 1:  
					$simage =imagecreatefromgif($destination);  
					break;  
					case 2:  
					$simage =imagecreatefromjpeg($destination);  
					break;  
					case 3:  
					$simage =imagecreatefrompng($destination);  
					break;  
					case 6:  
					$simage =imagecreatefromwbmp($destination);  
					break;  
					default:  
					die("不支持的文件类型");  
					exit;  
				}  
		  
				imagecopy($nimage,$simage,0,0,0,0,$image_size[0],$image_size[1]);  
				imagefilledrectangle($nimage,1,$image_size[1]-15,80,$image_size[1],$white);  
		  
				switch($watertype)  
				{  
					case 1:   //加水印字符串  
					imagestring($nimage,2,3,$image_size[1]-15,$waterstring,$black);  
					break;  
					case 2:   //加水印图片  
					$simage1 =imagecreatefromgif("xplore.gif");  
					imagecopy($nimage,$simage1,0,0,0,0,85,15);  
					imagedestroy($simage1);  
					break;  
				}  
		  
				switch ($iinfo[2])  
				{  
					case 1:  
					//imagegif($nimage, $destination);  
					imagejpeg($nimage, $destination);  
					break;  
					case 2:  
					imagejpeg($nimage, $destination);  
					break;  
					case 3:  
					imagepng($nimage, $destination);  
					break;  
					case 6:  
					imagewbmp($nimage, $destination);  
					//imagejpeg($nimage, $destination);  
					break;  
				}  
		  
				//覆盖原上传文件  
				imagedestroy($nimage);  
				imagedestroy($simage);  
			}  
		  
			if($imgpreview==1)  
			{  
			echo "<br>图片预览:<br>";  
			echo "<img src=\"".$destination."\" width=".($image_size[0]*$imgpreviewsize)." height=".($image_size[1]*$imgpreviewsize);  
			echo " alt=\"图片预览:\r文件名:".$destination."\r上传时间:\">";  
			}  
		}  
		$this->display();
	}
	
	//进入图库
	public function get_filetree(){
	$sku = I('get.sku','','htmlspecialchars');
	$dir = "public/images/".$sku;
	if (is_dir($dir)) {
		echo "<html><head><body>";
		if ($dh = opendir($dir)) {
			while (($file = readdir($dh)) !== false) {
				if($file != "." && $file != "..") {
					echo "<img src='/$dir/"."$file'>".'<br/>';
					echo $file.'<br/>';
				}
			}
			
		}
		echo "</body></head></html>";
	}
		closedir($dh);
	}
	
	
	public function test(){
		$data = M('product')->field('sku,default_styles,independent_product,brand,logo,product_material,product_type,weight,cost_price,supplier,addtime')->where(array('id'=>'422'))->select();
		$res = $this->push111($data);
	}
	
	
	/* 导出excel函数*/
    public function push111($data,$name='Excel'){
		$name = $_SESSION['user'];
		$acc_type = M('account')->field('cost_price,supplier')->where(array('username'=>$name))->find();
          //error_reporting(E_ALL);
          date_default_timezone_set('PRC');
		  
		  import("Org.Util.PHPExcel");
        import("Org.Util.PHPExcel.Worksheet.Drawing");
        import("Org.Util.PHPExcel.Writer.Excel2007");
		import("Org.Util.PHPExcel.Style.NumberFormat");
		import("Org.Util.PHPExcel.Style.Alignment");
		import("Org.Util.PHPExcel.Style.Color");
		
		import("Org.Util.PHPExcel.Style.Border");
        $objPHPExcel = new \PHPExcel();
        $objWriter = new \PHPExcel_Writer_Excel2007($objPHPExcel);
    
        $objActSheet = $objPHPExcel->getActiveSheet();
		
		
        $objActSheet->setCellValue('A1', 'SKU');    
             $objActSheet ->setCellValue('B1', '默认款式');
             $objActSheet ->setCellValue('C1', '线上产品');
			 $objActSheet->setCellValue('D1', '品牌');    
             $objActSheet ->setCellValue('E1', 'LOGO');
             $objActSheet ->setCellValue('F1', '产品材质');
			 $objActSheet->setCellValue('G1', "产品类型");    
             $objActSheet ->setCellValue('H1', "重量");
             $objActSheet ->setCellValue('I1', "成本价");
			 
			 $objActSheet->setCellValue('J1', "供应商");    
             $objActSheet ->setCellValue('K1', "添加时间");
							  
         /*以下就是对处理Excel里的数据， 横着取数据，主要是这一步，其他基本都不要改*/
        foreach($data as $k => $v){
             $k +=2;
             $objPHPExcel->setActiveSheetIndex(0);
                         //Excel的第A列，uid是你查出数组的键值，下面以此类推
             $objActSheet->setCellValue('A'.$k, $v['sku']);    
             $objActSheet ->setCellValue('B'.$k, $v['default_styles']);
             $objActSheet ->setCellValue('C'.$k, $v['independent_product']);
			 
			 $objActSheet->setCellValue('D'.$k, $v['brand']);    
             $objActSheet ->setCellValue('E'.$k, $v['logo']);
             $objActSheet ->setCellValue('F'.$k, $v['product_material']);
			 
			 
			 $objActSheet->setCellValue('G'.$k, $v['product_type']);    
             $objActSheet ->setCellValue('H'.$k, $v['weight']);
             $objActSheet ->setCellValue('I'.$k, $v['cost_price']);
			 
			 $objActSheet->setCellValue('J'.$k, $v['suppliersupplier']);    
             $objActSheet ->setCellValue('K'.$k, $v['addtime']);
            }
			
			$fileName = '产品目录表';
			$date = date("Y-m-d",time());
			$fileName .= "_{$date}.xls";
	
			$fileName = iconv("utf-8", "gb2312", $fileName);
			//重命名表
			// $objPHPExcel->getActiveSheet()->setTitle('test');
			//设置活动单指数到第一个表,所以Excel打开这是第一个表
			$objPHPExcel->setActiveSheetIndex(0);
			header('Content-Type: application/vnd.ms-excel');
			header("Content-Disposition: attachment;filename=\"$fileName\"");	//图片另存为
			header('Cache-Control: max-age=0');
	
			$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
			$objWriter->save('php://output'); //文件通过浏览器下载
            exit;
      }


	/**
     * 批量导出
     */
	public function daochu_excel_new(){
		$name = $_SESSION['user'];
		$acc_type = M('account')->field('cost_price,supplier')->where(array('username'=>$name))->find();
		$ids = I('get.tids','','htmlspecialchars');
		$id_list = explode(',',trim($ids,','));
		$custom = M('custom')->where(array('id'=>'1'))->find();
		foreach($id_list as $key=>$val){
			if($acc_type['supplier'] =='1'){
			$data[$key] = M('product')->field('sku,default_styles,price_type,brand,logo,product_material,product_type,weight,ali_lt,ali_gt,aliexpress,ioffer,	custom_one,custom_two,custom_three,custom_four,cost_price,supplier,buyer,addtime,own_product,fictitious_product')->where(array('id'=>$val))->find();
			}else{
				$data[$key] = M('product')->field('sku,default_styles,price_type,brand,logo,product_material,product_type,weight,ali_lt,ali_gt,aliexpress,ioffer,custom_one,custom_two,custom_three,custom_four,cost_price,buyer,addtime,own_product,fictitious_product')->where(array('id'=>$val))->find();

			}

		}
		foreach($data as $key=>$val){
			if($val['default_styles']=='1'){
				$data[$key]['default_styles']='是';
			}else{
				$data[$key]['default_styles']='否';
			}

//			if($val['independent_product']=='1'){
//				$data[$key]['independent_product']='是';
//			}else{
//				$data[$key]['independent_product']='否';
//			}
//
//			if($val['independent_product']==''){
//				$data[$key]['independent_product']='';
//			}
			if($val['logo']=='1'){
				$data[$key]['logo']='是';
			}else{
				$data[$key]['logo']='否';
			}
		}

		error_reporting(E_ALL);
		date_default_timezone_set('PRC');

		import("Org.Util.PHPExcel");
		import("Org.Util.PHPExcel.Worksheet.Drawing");
		import("Org.Util.PHPExcel.Writer.Excel2007");
		import("Org.Util.PHPExcel.Style.NumberFormat");
		import("Org.Util.PHPExcel.Style.Alignment");
		import("Org.Util.PHPExcel.Style.Color");

		import("Org.Util.PHPExcel.Style.Border");
		$objPHPExcel = new \PHPExcel();
		$objWriter = new \PHPExcel_Writer_Excel2007($objPHPExcel);

		$objActSheet = $objPHPExcel->getActiveSheet();
		if($acc_type['supplier'] =='1'){
			$objActSheet ->setCellValue('A1', 'SKU');
			$objActSheet ->setCellValue('B1', '默认款式');
			$objActSheet ->setCellValue('C1', '价格类型');
			$objActSheet ->setCellValue('D1', "品牌");
			$objActSheet ->setCellValue('E1', "LOGO");
			$objActSheet ->setCellValue('F1', "产品材质");
			$objActSheet ->setCellValue('G1', "产品类型");
            $objActSheet ->setCellValue('H1', '自主订货产品');
            $objActSheet ->setCellValue('I1', '虚拟产品');
			$objActSheet ->setCellValue('J1', "重量单位：g");
			$objActSheet ->setCellValue('K1', '成本价单位：￥');
			$objActSheet ->setCellValue('L1', "批发散货价单位：$");
			$objActSheet ->setCellValue('M1', "批发订货价单位：$");
			$objActSheet ->setCellValue('N1', "零售价：$");
//			$objActSheet ->setCellValue('M1', "IOFFER指导价单位：$");
			$objActSheet ->setCellValue('O1', $custom['one']);
			$objActSheet ->setCellValue('P1', $custom['two']);
			$objActSheet ->setCellValue('Q1', $custom['three']);
			$objActSheet ->setCellValue('R1', $custom['four']);
			$objActSheet ->setCellValue('S1', "供应商");
			$objActSheet ->setCellValue('T1', "采购员");
			$objActSheet ->setCellValue('U1', "产品创建时间");

			 //以下就是对处理Excel里的数据， 横着取数据，主要是这一步，其他基本都不要改
			foreach($data as $k => $v){
				 $k +=2;
				 $objPHPExcel->setActiveSheetIndex(0);
							 //Excel的第A列，uid是你查出数组的键值，下面以此类推
				 $objActSheet ->setCellValue('A'.$k, $v['sku']);
				 $objActSheet ->setCellValue('B'.$k, $v['default_styles']);
//				 $objActSheet ->setCellValue('C'.$k, $v['independent_product']);
				 $objActSheet ->setCellValue('C'.$k, $v['price_type']);
				 $objActSheet ->setCellValue('D'.$k, $v['brand']);
				 $objActSheet ->setCellValue('E'.$k, $v['logo']);
				 $objActSheet ->setCellValue('F'.$k, $v['product_material']);
				 $objActSheet ->setCellValue('G'.$k, $v['product_type']);
                 $objActSheet ->setCellValue('H'.$k, $v['own_product']);
                 $objActSheet ->setCellValue('I'.$k, $v['fictitious_product']);
				 $objActSheet ->setCellValue('J'.$k, $v['weight']);
				 $objActSheet ->setCellValue('K'.$k, $v['cost_price']);
				 $objActSheet ->setCellValue('L'.$k, $v['ali_lt']);
				 $objActSheet ->setCellValue('M'.$k, $v['ali_gt']);
				 $objActSheet ->setCellValue('N'.$k, $v['aliexpress']);
				 $objActSheet ->setCellValue('O'.$k, $v['custom_one']);
				 $objActSheet ->setCellValue('P'.$k, $v['custom_two']);
				 $objActSheet ->setCellValue('Q'.$k, $v['custom_three']);
				 $objActSheet ->setCellValue('R'.$k, $v['custom_four']);
				 $objActSheet ->setCellValue('S'.$k, $v['supplier']);
				 $objActSheet ->setCellValue('T'.$k, $v['buyer']);
				 $objActSheet ->setCellValue('U'.$k, $v['addtime']);

			}
		}else{
			$objActSheet ->setCellValue('A1', 'SKU');
			$objActSheet ->setCellValue('B1', '默认款式');
			$objActSheet ->setCellValue('C1', '价格类型');
			$objActSheet ->setCellValue('D1', "品牌");
			$objActSheet ->setCellValue('E1', "LOGO");
			$objActSheet ->setCellValue('F1', "产品材质");
			$objActSheet ->setCellValue('G1', "产品类型");
            $objActSheet ->setCellValue('H1', '自主订货产品');
            $objActSheet ->setCellValue('I1', '虚拟产品');
			$objActSheet ->setCellValue('J1', "重量单位：g");
			$objActSheet ->setCellValue('K1', '成本价单位：￥');
            $objActSheet ->setCellValue('L1', "批发散货价单位：$");
            $objActSheet ->setCellValue('M1', "批发订货价单位：$");
            $objActSheet ->setCellValue('N1', "零售价：$");
//			$objActSheet ->setCellValue('M1', "IOFFER指导价单位：$");
            $objActSheet ->setCellValue('O1', $custom['one']);
            $objActSheet ->setCellValue('P1', $custom['two']);
            $objActSheet ->setCellValue('Q1', $custom['three']);
            $objActSheet ->setCellValue('R1', $custom['four']);
            $objActSheet ->setCellValue('S1', "采购员");
            $objActSheet ->setCellValue('T1', "产品创建时间");

		 //以下就是对处理Excel里的数据， 横着取数据，主要是这一步，其他基本都不要改
		foreach($data as $k => $v){
			 $k +=2;
			 $objPHPExcel->setActiveSheetIndex(0);
						 //Excel的第A列，uid是你查出数组的键值，下面以此类推
			 	 $objActSheet ->setCellValue('A'.$k, $v['sku']);
				 $objActSheet ->setCellValue('B'.$k, $v['default_styles']);
//				 $objActSheet ->setCellValue('C'.$k, $v['independent_product']);
				 $objActSheet ->setCellValue('C'.$k, $v['price_type']);
				 $objActSheet ->setCellValue('D'.$k, $v['brand']);
				 $objActSheet ->setCellValue('E'.$k, $v['logo']);
				 $objActSheet ->setCellValue('F'.$k, $v['product_material']);
				 $objActSheet ->setCellValue('G'.$k, $v['product_type']);
                $objActSheet ->setCellValue('H'.$k, $v['own_product']);
                $objActSheet ->setCellValue('I'.$k, $v['fictitious_product']);
				 $objActSheet ->setCellValue('J'.$k, $v['weight']);
				 $objActSheet ->setCellValue('K'.$k, $v['cost_price']);
				 $objActSheet ->setCellValue('L'.$k, $v['ali_lt']);
				 $objActSheet ->setCellValue('M'.$k, $v['ali_gt']);
                $objActSheet ->setCellValue('N'.$k, $v['aliexpress']);
                $objActSheet ->setCellValue('O'.$k, $v['custom_one']);
                $objActSheet ->setCellValue('P'.$k, $v['custom_two']);
                $objActSheet ->setCellValue('Q'.$k, $v['custom_three']);
                $objActSheet ->setCellValue('R'.$k, $v['custom_four']);
                $objActSheet ->setCellValue('S'.$k, $v['buyer']);
                $objActSheet ->setCellValue('T'.$k, $v['addtime']);
		}
	}
		$fileName = '产品目录表';
		$date = date("Y-m-d",time());
		$fileName .= "_{$date}.xls";
		//$res = $this->exportexcel($data,$title,$fileName);


			//重命名表
			 $objPHPExcel->getActiveSheet()->setTitle('test');
			//设置活动单指数到第一个表,所以Excel打开这是第一个表
			$objPHPExcel->setActiveSheetIndex(0);
			header('Content-Type: application/vnd.ms-excel');
			header("Content-Disposition: attachment;filename=\"$fileName\"");	//图片另存为
			header('Cache-Control: max-age=0');

			$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
			$objWriter->save('php://output'); //文件通过浏览器下载
			exit;
	}

	//2017-01-13  备份导出部份属性
	/*public function daochu_excel_new(){
		$name = $_SESSION['user'];
		$acc_type = M('account')->field('cost_price,supplier')->where(array('username'=>$name))->find();
		$ids = I('get.tids','','htmlspecialchars');
		$id_list = explode(',',trim($ids,','));
		foreach($id_list as $key=>$val){
			if($acc_type['supplier'] =='1'){
			$data[$key] = M('product')->field('sku,default_styles,independent_product,brand,logo,product_material,product_type,weight,cost_price,supplier,addtime')->where(array('id'=>$val))->find();
			}else{
				$data[$key] = M('product')->field('sku,default_styles,independent_product,brand,logo,product_material,product_type,weight,cost_price,addtime')->where(array('id'=>$val))->find();
			}
			
		}
		foreach($data as $key=>$val){
			if($val['default_styles']=='1'){
				$data[$key]['default_styles']='是';
			}else{
				$data[$key]['default_styles']='否';
			}
			
			if($val['independent_product']=='1'){
				$data[$key]['independent_product']='是';
			}else{
				$data[$key]['independent_product']='否';
			}
			
			if($val['independent_product']==''){
				$data[$key]['independent_product']='';
			}
			if($val['logo']=='1'){
				$data[$key]['logo']='是';
			}else{
				$data[$key]['logo']='否';
			}
		}
		
		error_reporting(E_ALL);
		date_default_timezone_set('PRC');
		  
		import("Org.Util.PHPExcel");
		import("Org.Util.PHPExcel.Worksheet.Drawing");
		import("Org.Util.PHPExcel.Writer.Excel2007");
		import("Org.Util.PHPExcel.Style.NumberFormat");
		import("Org.Util.PHPExcel.Style.Alignment");
		import("Org.Util.PHPExcel.Style.Color");
		
		import("Org.Util.PHPExcel.Style.Border");
		$objPHPExcel = new \PHPExcel();
		$objWriter = new \PHPExcel_Writer_Excel2007($objPHPExcel);
	
		$objActSheet = $objPHPExcel->getActiveSheet();
		
		if($acc_type['supplier'] =='1'){
			$objActSheet->setCellValue('A1', 'SKU');    
			$objActSheet ->setCellValue('B1', '默认款式');
			$objActSheet ->setCellValue('C1', '线上产品');
			$objActSheet->setCellValue('D1', '品牌');    
			$objActSheet ->setCellValue('E1', 'LOGO');
			$objActSheet ->setCellValue('F1', '产品材质');
			$objActSheet->setCellValue('G1', "产品类型");    
			$objActSheet ->setCellValue('H1', "重量");
			$objActSheet ->setCellValue('I1', "成本价");
			$objActSheet->setCellValue('J1', "供应商");    
			$objActSheet ->setCellValue('K1', "添加时间");
								  
			 //以下就是对处理Excel里的数据， 横着取数据，主要是这一步，其他基本都不要改
			foreach($data as $k => $v){
				 $k +=2;
				 $objPHPExcel->setActiveSheetIndex(0);
							 //Excel的第A列，uid是你查出数组的键值，下面以此类推
				 $objActSheet->setCellValue('A'.$k, $v['sku']);    
				 $objActSheet ->setCellValue('B'.$k, $v['default_styles']);
				 $objActSheet ->setCellValue('C'.$k, $v['independent_product']);
				 
				 $objActSheet->setCellValue('D'.$k, $v['brand']);    
				 $objActSheet ->setCellValue('E'.$k, $v['logo']);
				 $objActSheet ->setCellValue('F'.$k, $v['product_material']);
				 
				 
				 $objActSheet->setCellValue('G'.$k, $v['product_type']);    
				 $objActSheet ->setCellValue('H'.$k, $v['weight']);
				 $objActSheet ->setCellValue('I'.$k, $v['cost_price']);
				 
				 $objActSheet->setCellValue('J'.$k, $v['supplier']);    
				 $objActSheet ->setCellValue('K'.$k, $v['addtime']);
			}
		}else{
			$objActSheet->setCellValue('A1', 'SKU');    
		$objActSheet ->setCellValue('B1', '默认款式');
		$objActSheet ->setCellValue('C1', '线上产品');
		$objActSheet->setCellValue('D1', '品牌');    
		$objActSheet ->setCellValue('E1', 'LOGO');
		$objActSheet ->setCellValue('F1', '产品材质');
		$objActSheet->setCellValue('G1', "产品类型");    
		$objActSheet ->setCellValue('H1', "重量");
		$objActSheet ->setCellValue('I1', "成本价");
		
		$objActSheet ->setCellValue('J1', "添加时间");
							  
		 //以下就是对处理Excel里的数据， 横着取数据，主要是这一步，其他基本都不要改
		foreach($data as $k => $v){
			 $k +=2;
			 $objPHPExcel->setActiveSheetIndex(0);
						 //Excel的第A列，uid是你查出数组的键值，下面以此类推
			 $objActSheet->setCellValue('A'.$k, $v['sku']);    
			 $objActSheet ->setCellValue('B'.$k, $v['default_styles']);
			 $objActSheet ->setCellValue('C'.$k, $v['independent_product']);
			 
			 $objActSheet->setCellValue('D'.$k, $v['brand']);    
			 $objActSheet ->setCellValue('E'.$k, $v['logo']);
			 $objActSheet ->setCellValue('F'.$k, $v['product_material']);
			 
			 
			 $objActSheet->setCellValue('G'.$k, $v['product_type']);    
			 $objActSheet ->setCellValue('H'.$k, $v['weight']);
			 $objActSheet ->setCellValue('I'.$k, $v['cost_price']);
			 
			 $objActSheet ->setCellValue('J'.$k, $v['addtime']);
		}
			
			
		//$filename = "excel";
		if($acc_type['supplier'] =='1'){
			$title = array('SKU','默认款式','线上产品','品牌','LOGO','产品材质','产品类型','重量','成本价','供应商','创建时间');
			}else{
				$title = array('SKU','默认款式','线上产品','品牌','LOGO','产品材质','产品类型','重量','成本价','创建时间');
			}
		
		$res = $this->exportexcel($data,$title,$filename);
	}
	$fileName = '产品目录表';
			$date = date("Y-m-d",time());
			$fileName .= "_{$date}.xls";
		
			//重命名表
			// $objPHPExcel->getActiveSheet()->setTitle('test');
			//设置活动单指数到第一个表,所以Excel打开这是第一个表
			$objPHPExcel->setActiveSheetIndex(0);
			header('Content-Type: application/vnd.ms-excel');
			header("Content-Disposition: attachment;filename=\"$fileName\"");	//图片另存为
			header('Cache-Control: max-age=0');
	
			$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
			$objWriter->save('php://output'); //文件通过浏览器下载
			exit;
	}
*/	

	public function export_download(){
		//$source_page = reset(explode('.',end(explode('/',$_SERVER['HTTP_REFERER']))));
		$source_page = trim($_GET['source_page']);
		//$source_page = $_GET['source_page']=='select_history_pur'?'历史采购':'历史采购明细';
		if($source_page=='product_circulation'){
			$table = 'order';
			$title = array('id','SKU','交摄时间','完成图片时间','上传完成时间','阿里巴巴国际站','速卖通','敦煌','全球通','亚马逊');
			$data = M('circulation')->field('id,sku,time1,time2,time3,time4,time5,time6,time7,time8,time9,time10,time11')->where(array('id'=>array('in',trim($_GET['ids'],','))))->order('id desc')->select();
			for($i=0;$i<count($data);$i++){
				//$where = " porder_number = '".$data[$i]['porder_number']."' and purchase_quantity>0";
				$data[$i]['order_info']=M('finish_order_info')->field('supplier,sku,cost_price purchase_price ,purchase_quantity,purchase_quantity*cost_price total,order_number,quantity product_num,premarks')->order('time12 desc')->select();
				//var_dump(M()->getLastSql());
				$data[$i]['porder_number']='';
			}

			$res = $this->exportexcel($data,$title,$source_page=='product_circulation'?'新品运转流程':'新品上线',$title1);
		}
		if($source_page=='select_history_detailed'){
			$title = array('供应商','SKU','采购单价','采购数量','总价','订单号','产品数量','备注');
			$data = M('order_info')->field('supplier,sku,purchase_price ,quantity,quantity*purchase_price total,order_number,quantity,premarks')->where(array('id'=>array('in',trim($_GET['tids'],','))))->order('id desc')->select();
		}


		if($source_page=='product_offshelf'){

			$title = array('id','SKU','产品下架时间','下架原因','阿里巴巴国际站','速卖通','敦煌','全球通','亚马逊');
			$data = M('off_shelf')->field('id,sku,offshelf_time,offshelf_reason,time1,time2,time3,time4,time5,time6,time7,time8')->where(array('id'=>array('in',trim($_GET['ids'],','))))->order('id desc')->select();

			$res = $this->exportexcel($data,$title,$source_page=='product_offshelf'?'下架信息':'下架信息导出',$title1);
		}
		/* 2017-04-28 chen */
		$title1 = array('供应商','SKU','采购单价','采购数量','总价','订单号','产品数量','备注');
		//var_dump($data);die;	
		
		/* 2017-04-28 chen */

	}

	public function add_date(){
		if(IS_GET){
			
			$data = I('get.');
			//dump($data);exit;
			
			
			$id= $data['id'];
		}
		//dump($data);exit;
		//将时间写入对应的行列数据中
		$c = M('circulation');
		$res = $c->where(array('id'=>$id))->save($data);
		//echo $res;exit;
		if($res){
			$this->success('成功输入日期');

		}else{
			$this->error('日期添加失败');
		}
	}

	public function offshelf_date(){
		if(IS_GET){
			
			$data = I('get.');
			//dump($data);exit;
			
			
			$id= $data['id'];
		}
		//dump($data);exit;
		//将时间写入对应的行列数据中
		$c = M('off_shelf');
		$res = $c->where(array('id'=>$id))->save($data);
		//echo $res;exit;
		if($res){
			$this->success('成功输入日期');

		}else{
			$this->error('日期添加失败');
		}
	}



	//历史采购单查询
	public function select_history_pur(){
		header("Content-type: text/html; charset=utf-8");
		$quanxian = M('account')->field('select')->where(array('username'=>$_SESSION['user']))->find();
		if(!$quanxian['select']){
			$this->assign('message','该用户暂无权限！');
			$this->display('error');exit;
		}
		//$where = '';//'status=2';//设置默认条件
		//判断GET参数
		$data['starttime'] = $_GET['delivery_time_start'];
		$data['endtime'] = $_GET['delivery_time_end'];
		$data['buyer'] = $_GET['buyer'];
		$pagesize = $_GET['pagesize']?$_GET['pagesize']:10;
		$nowpage = $_GET['page']?$_GET['page']:1;
		$limit = ''.($pagesize*$nowpage-$pagesize).','.$pagesize;
		$where = " finish_time!='0000-00-00 00:00:00' and finish_buyer !='' ";
		if(!empty($_GET)){
			//var_dump($_GET);
			$where .=  $_GET['delivery_time_start']?" and finish_time>='".$_GET['delivery_time_start']."'":'';
			$where .=  $_GET['delivery_time_end']?" and finish_time<='".$_GET['delivery_time_end']."'":'';
			$where .=  $_GET['buyer']?" and finish_buyer ='".$_GET['buyer']."'":'';
			
			$where = trim($where,' and');
		}
		$buyer_list = M('order_info')->field('buyer')->group('buyer')->select();
		//$count = M('order')->field('order.id,order.order_number,order_info.buyer,order.finish_time')->join('order_info on order.order_number=order_info.order_number')->where($where)->group('order_info.order_number')->order('order.id desc')->count();
		$count = M('finish_order')->field('id')->where($where)->count();
		//$count = M()->query("select count(xx.id) count from (SELECT order.id,order.porder_number,order_info.buyer,order.finish_time FROM `order` INNER JOIN order_info on order.order_number=order_info.order_number WHERE ".$where ." GROUP BY order_info.order_number ORDER BY order.finish_time desc) xx limit 1")[0]['count'];
		$countpage = ceil($count/$pagesize);
		/* 2017-04-28 chen */
		//$list = M('order')->field('order.id,order.order_number,order_info.buyer,order.finish_time,order.porder_number')->join('order_info on order.order_number=order_info.order_number')->where($where)->group('order_info.order_number')->order('order.id desc')->limit($limit)->select();
		/* 2017-04-28 chen */
		$list = M('finish_order')->field('id,porder_number,finish_buyer buyer,finish_time,porder_number,finish_order_number')->where($where)->order('finish_time  desc')->limit($limit)->select();
		$this->assign('data',$data);
		$this->assign('countpage',$countpage);
		$this->assign('nowpage',$nowpage);
		$this->assign('pagesize',$pagesize);
		$this->assign('count',$count);
		//var_dump($list);
		$this->assign('list',$list);
		$this->assign('buyer_list',$buyer_list);
		$this->display();

	}



	//获取批量导出id
	public function get_xxxxxx_id(){
		$where = " finish_time!='0000-00-00 00:00:00' and finish_buyer !='' ";
		$where .=  $_GET['start']?" and finish_time>='".$_GET['start']."'":'';
		$where .=  $_GET['end']?" and finish_time<='".$_GET['end']."'":'';
		$data = M('finish_order')->field('id')->where($where)->select();
		//var_dump($data);die;
		$str = '';
		foreach($data as $v){
			$str .=$v['id'].',';
		}
		if(trim($str)==''){
			$this->error('错误操作！');exit;
		}
		$url = U("export_download").'?source_page=select_history_pur&tids='.trim($str);
		header('Location:'.$url);
	}



	public function del_circulation(){
		$table ='account';
		$id = I('get.cir_id');
		//echo $id;
		//查询该用户是否有删除权限
		$p = M('account')->field('del_circulation')->where(array('username'=>$_SESSION['user']))->find();
		if($p['del_circulation']==0){
			$this->error('该用户暂无权限！');exit;
		}


		$c = "circulation";
		if($p['del_circulation']==1){
			if(M($c)->where(array('id'=>$id))->delete()){
				$this->success('删除成功！',U('Product/product_circulation'));exit;
			}else{
				$this->error('删除失败！', U('Product/product_circulation'));exit;
			}
		}else{
			$this->error('数据不存在！请输入正确数据', U('Product/product_circulation'));
		}
			
		
	}


	public function product_offshelf(){

		//页码
		$count = M('off_shelf')->field('id')->count();
		$pagesize = $_POST['pagesize']?$_POST['pagesize']:10;
		$nowpage = $_POST['page']?$_POST['page']:1;
		$limit = ''.($pagesize*$nowpage-$pagesize).','.$pagesize;
		$list = M('off_shelf')->order('id  desc')->limit($limit)->select();
		$countpage = ceil($count/$pagesize);
		

		$this->assign('page',$page);
		$this->assign('countpage',$countpage);
		$this->assign('nowpage',$nowpage);
		$this->assign('pagesize',$pagesize);
		$this->assign('count',$count);
		$this->assign('list',$list);

		$platform_name = M('platform');
		//只有一条记录， 所以用 find . 查找平台信息
		$data = $platform_name->find();
		
		if(IS_POST){

			$offshelf_post_data = I('post.');
			$where = array();

			//查询 where 条件组合

			//按sku
			if($offshelf_post_data['sku']){
				$where['sku'] = array('sku',$offshelf_post_data['sku']);
			}

			//按下架时间
			if($offshelf_post_data['off_time_start'] && $offshelf_post_data['off_time_end']){
				$where['offshelf_time'] = array(
					array('egt',$offshelf_post_data['off_time_start']),
					array('elt',$offshelf_post_data['off_time_end']." 23:59:59"),


				);
			}

			//按下架原因
			if($offshelf_post_data['offshelf_reason']){
				$where['offshelf_reason'] = array('eq',$offshelf_post_data['offshelf_reason']);
			}


			$offshelf = M('off_shelf')->where($where)->select();
			$this->assign('offshelf',$offshelf);
			return $this->display();


		}

		//off_shelf表
		$offshelf = M('off_shelf')->select();
		
		//dump($offshelf);exit;

		$this->assign('data',$data);
		$this->assign('offshelf',$offshelf);

		return $this->display();
	}

	// 产品下架情况 ： 提交新添下架信息到数据库   
	public function offshelf_post(){

		if(IS_POST){
			$data = I('post.');

			$res = M('off_shelf')->add($data);

			if($res){
				$this->success('成功添加下架信息； 注意登记平台下架时间');
			}else{
				$this->error('下架信息添加失败');exit;
			}
		}
	}


	public function del_offshelf_infos(){
		if(IS_GET){
			$data = I('get.');
			$s= M('off_shelf');
			$w = M('account');
			$power_type=$w->where(array('username' => $data['username']))->field('del_offshelf_infos')->find();
			//dump($power_type);die;
			if($power_type['del_offshelf_infos']=="1"){
				$res = $s->delete($data['offshelf_id']);
				if($res){
					$this->success('成功删除下架信息；');
				}else{
					$this->error('下架信息删除失败');exit;
				}

			}else{
				$this->error('您没有权限删除该下架信息');
			}

			
		}
	}


	 /**
     * 产品销售统计
     * @return mixed
     * @author wuzhc 2018-03-09
     */
    public function product_sale_stat()
    {

        $delivery_time_start = I('get.delivery_time_start','','htmlspecialchars'); // 发货开始时间
        $delivery_time_end = I('get.delivery_time_end','','htmlspecialchars'); // 发货结束时间
        $sku = I('get.sku','','htmlspecialchars'); 
        $product_dev = I('get.product_dev','','htmlspecialchars'); // 产品开发人员
        $own_product = I('get.own_product','','htmlspecialchars'); // 自主订货产品
        $product_type = I('get.product_type','','htmlspecialchars'); // 产品类型
        $add_time_start = I('get.add_time_start','','htmlspecialchars'); // 产品创建开始时间
        $add_time_end = I('get.add_time_end','','htmlspecialchars'); // 产品创建结束时间
        $pageNo = I('get.pageNo', 1, 'intval');  //获取当前页
        $pageSize = I('get.pageSize', 10, 'intval');  //获取转换的每页显示条数
        $_SESSION['req'] 		   = I('get.req','','htmlspecialchars');
       // $_SESSION['req'] 	  =   (empty($_REQUEST['req']))?($_REQUEST['req']):1;

        
        //$_SESSION['req'] = 0;

       /* if(IS_GET){
        	if(!$_REQUEST['req'])
        		$_SESSION['req'] = 1;
        }*/


        
        	
        //$test_data = I('get.');
        //dump($test_data);die;
      	//echo "session=".$_SESSION['req'];die;

        //$last_30_day = date('Y-m-d H:i:s', time() - 60*60*24*30);  //生成日期。 默认显示30天内的数据

        $args = array(
            'sku' => $sku,
            'pageNo' => $pageNo,
            'pageSize' => $pageSize,
            'product_dev' => $product_dev,
            'own_product' => $own_product,
            'product_type' => $product_type,
            'add_time_start' => $add_time_start,
            'add_time_end' => $add_time_end,
            'delivery_time_start' => $delivery_time_start,
            'delivery_time_end' => $delivery_time_end,
            //'req'				=> $_SESSION['req'],   //提交的标志， 如果为空，就走默认显示30天内记录的SQL语句分支

        );

        if ($delivery_time_start) {
            $this->assign('delivery_time_start',$delivery_time_start);
        }
        if ($delivery_time_end) {
            $this->assign('delivery_time_end',$delivery_time_end);
        }
        if ($sku) {
            $this->assign('sku',$sku);
        }
        if ($product_dev) {
            $this->assign('product_dev',$product_dev);
        }
        if ($product_type) {
            $this->assign('product_type',$product_type);
        }
        if ($own_product) {
            $this->assign('own_product',$own_product);
        }
        if ($add_time_start) {
            $this->assign('add_time_start',$add_time_start);
        }
        if ($add_time_end) {
            $this->assign('add_time_end',$add_time_end);
        }

        $count['count'] = $this->get_sale_stat_total($args);
        $count['pageSize'] = $pageSize;
        $count['countpage'] = ceil($count['count'] / $pageSize);
        $count['pageNo'] = max(min($pageNo, $count['countpage']),1);
        $count['num'] = $count['countpage']-4;
        $this->assign('count', $count);

        /** @var \Think\Controller $this */
        //dump($this->get_sale_stat_list($args));exit;
        $this->assign('products', $this->get_sale_stat_list($args));
        return $this->display();
    }


    /**
     * 导出产品销售统计
     * @author wuzhc 2018-03-09
     */
    public function import_sale_stat()
    {
        $delivery_time_start = I('get.delivery_time_start','','htmlspecialchars'); // 发货开始时间
        $delivery_time_end = I('get.delivery_time_end','','htmlspecialchars'); // 发货结束时间
        $sku = I('get.sku','','htmlspecialchars');
        $product_dev = I('get.product_dev','','htmlspecialchars'); // 产品开发人员
        $own_product = I('get.own_product','','htmlspecialchars'); // 自主订货产品
        $product_type = I('get.product_type','','htmlspecialchars'); // 产品类型
        $add_time_start = I('get.add_time_start','','htmlspecialchars'); // 产品创建开始时间
        $add_time_end = I('get.add_time_end','','htmlspecialchars'); // 产品创建结束时间
        //$req  		   = I('get.req','','htmlspecialchars');         //提交的标志， 如果为空，就走默认显示30天内记录的SQL语句分支

        $args = array(
            'sku' => $sku,
            'product_dev' => $product_dev,
            'own_product' => $own_product,
            'product_type' => $product_type,
            'add_time_start' => $add_time_start,
            'add_time_end' => $add_time_end,
            'delivery_time_start' => $delivery_time_start,
            'delivery_time_end' => $delivery_time_end,
            //'req'				=> $req,
        );

        $title = array(
            'sku', '主图', '产品开发人员', '产品类型', '品牌', '自主订货产品', '供应商',
            '销售总数量', '成本价', '实际销售总金额', '统计时间', '产品创建时间'
        );
        $products = $this->get_sale_stat_list($args);
        $this->exportexcel($products, $title, '产品销售统计');
    }

  
    /**
     * 统计销售产品列表
     * @param $args
     * @return mixed
     * @author wuzhc 2018-03-09
     */
    protected function get_sale_stat_list($args)
    {
        $model = M('order_info');
       /*$i = $model->query($this->find_sale_stat_sql($args));
        dump($i);echo "<br>".$this->find_sale_stat_sql($args);exit;*/
         //var_dump($model->getDbError());exit;
        return $model->query($this->find_sale_stat_sql($args));

       
    }

    /**
     * 统计销售产品总数
     * @param $args
     * @return mixed
     * @author wuzhc 2018-03-09
     */
    protected function get_sale_stat_total($args)
    {
        unset($args['pageNo'], $args['pageSize']);
      

        $res = M('order_info')->query($this->find_sale_stat_sql($args));
        
        //echo $this->find_sale_stat_sql($args);exit;
       // echo count($res);die;
        return is_array($res) ? count($res) : 0;
    }

    /**
     * 销售产品sql
     * @param $args
     * @return string
     * @author wuzhc 2018-03-09
     */
    protected function find_sale_stat_sql($args)
    {
        $delivery_time_start = $args['delivery_time_start'];  // 发货开始时间
        $delivery_time_end = $args['delivery_time_end']; // 发货结束时间
        $sku = $args['sku'];
        $product_dev = $args['product_dev']; // 产品开发人员
        $own_product = $args['own_product']; // 自主订货产品
        $product_type = $args['product_type']; // 产品类型
        $add_time_start = $args['add_time_start']; // 产品创建开始时间
        $add_time_end = $args['add_time_end']; // 产品创建结束时间
        $pageNo = $args['pageNo'];
        $pageSize = $args['pageSize'];
        $req      = $args['req'];

        $sql = 'select a.sku,a.main_pic,c.custom_four as product_dev,c.product_type,c.brand,c.own_product,c.supplier,sum(quantity) as sale_num, c.cost_price, sum(purchase_price*quantity) as sale,b.delivery_time,c.addtime ';
        $sql .= 'from order_info a ';
        $sql .= 'inner join `order` b on a.order_number = b.order_number ';
        $sql .= 'inner join `product` c on a.sku = c.sku ';

        /*
        
        a.sku | a.main_pic | product_dev | c.product_type | c.brand | c.own_product | c.supplier | sale_num | c.cost_price | sale | b.delivery_time | c.addtime

        a  => order_info 表  (a.sku,a.main_pic)    a.order_number = b.order_number

        b => order 表  （b.delivery_time）

        c => product 表  (c.product_type , c.brand,c.own_product,c.supplier,c.cost_price,c.addtime)


        */

        $where = '';


        if ($delivery_time_start) {
            $where .= 'b.delivery_time >= "' . $delivery_time_start . '" and ';
        }
        if ($delivery_time_end) {
            $where .= 'b.delivery_time <= "' . $delivery_time_end . ' 23:59:59" and ';
        }
        if ($sku) {
            $where .= 'a.sku = "' . $sku . '" and ';
        }
        if ($product_dev) {
            $where .= 'c.custom_four = "' . $product_dev . '" and ';
        }
        if ($product_type) {
            $where .= 'c.product_type = "' . $product_type . '" and ';
        }
        if ($own_product) {
            $where .= 'c.own_product = "' . $own_product . '" and ';
        }
        if ($add_time_start) {
            $where .= 'c.addtime >= "' . $add_time_start . '" and ';
        }
        if ($add_time_end) {
            $where .= 'c.addtime <= "' . $add_time_end . ' 23:59:59" and ';
        }

        
        

        if ($where) {
            $sql .= 'where ' . rtrim($where, ' and ') . ' ';
        }


      //记号
        //默认输出最近30天
        // 当没有任何提交动作就走如下 分支， 拼装出 默认显示 30天内记录的 sql语句
        if($_SESSION['req']==0){
        	//echo $_SESSION['req'];die;

        	//如果没有提交， $where就为空， 将delivery_time >= 30天的条件赋值给$where， 默认输出 30天内的数据，
        	$last_30_day = date('Y-m-d H:i:s', time() - 60*60*24*30);  //生成日期。 默认显示30天内的数据 
        	$where='b.delivery_time >="'.$last_30_day.'"';

        	$sql .= 'where ' . rtrim($where, ' and ') . ' ';

        	$pageNo = $args['pageNo'];  //获取当前页
        	$pageSize = $args['pageSize'];  //获取转换的每页显示条数

        	//按delivery_time 排列
        	$sql .= 'group by a.sku order by b.delivery_time desc ';
        	if ($pageNo && $pageSize) {
           		 $sql .= 'limit ' . ($pageNo - 1) * $pageSize . ',' . $pageSize . ' ';
       		}
        	//echo "Default:  ".$sql."<br>";exit;
        	return $sql;
        }



        $sql .= 'group by a.sku ';
        

        if ($pageNo && $pageSize) {
            $sql .= 'limit ' . ($pageNo - 1) * $pageSize . ',' . $pageSize . ' ';
        }

        //echo "提交后sql=： ".$sql."<br>";exit;
        return $sql;
    }


    /**
     * 产品回收
     * @param $args
     * @return string
     * @author wuzhc 2018-03-09
     */
    //批量回收产品
    public function multi_recycle_pro()
    {
    	//权限判断
    	$p = M('account')->field('recycle_product')->where(array('username'=>$_SESSION['user']))->find();
        if(!$p['recycle_product']){
            $this->error('该用户暂无权限！');exit;
        }

        $ids = trim(I('get.tids','','htmlspecialchars'),'');
        if (empty($ids)) {
            $this->error("请勾选要回收的产品!");exit();
        }

        $ids = explode(',',trim($ids,','));
        foreach ($ids as $id) {
            if (empty($id)) {
                continue;
            }
            $product = M('product')->where(array('id' => $id))->find();
            if (!$product || $product->status == 2) {
                continue;
            }
            M('product')->where(array('id' => $id))->save(array('status' => 2));
        }
        header('Location:'.$_SERVER['HTTP_REFERER']);
    }


	
	

	
}
